[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] Et C spørgsmål især om pointere



On 11 Jul 2000, Anders Melchiorsen wrote:

> Mads Bondo Dydensborg <sslug@sslug> skrev:
> 
> > Hvis du tester vil du finde - det gjorde jeg ihvertfald - at
> > sizeof(unsigned long * arg) != sizeof(unsigned long arg[0]) == 0 
> 
> "unsigned long navn[0]" er et array på ingen ulongs. Det bruges oftest
> som sidste element i en struct, hvor man ønsker at  navn  skal have en
> variabel længde. Man kan så vha. malloc reservere størrelsen af
> structen plus så mange elementer, man vil have i dette specielle
> objekt.
> 

Jeg ved det :-)

> 
> For eksempel
> 
> 
> struct person {
>         unsigned int alder;
>         char navn[0];
> };
> 
> struct person* p = malloc(sizeof(struct person) + strlen(string) + 1);

Jep, det her er standard måden. 

Mit problem var, at jeg dels skulle have tingene malloc'ed to forskellige
steder (struct i normal ram, mens "resten" skulle bindes til nogle
specielle fysiske stede), dels at jeg skulle bruge en anden type end det
[0] arrayet var erklæret som.

Jeg fandt ud af at det under alle omstændigheder blev opfattet af gcc som
en pointer, så det var faktisk ikke så slemt at typecaste det. Jeg var
bare råforvirret.

Mads

-- 
Mads Bondo Dydensborg.                               sslug@sslug
You know you're a Linux geek when...

    You feel the desire to master vi.

                                                - segfault



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:08 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *