[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



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.


For eksempel


struct person {
        unsigned int alder;
        char navn[0];
};

struct person* p = malloc(sizeof(struct person) + strlen(string) + 1);


hvis man vil have et objekt som netop har plads til den streng, som
string peger på. Når man tilgår navnet gennem p->navn er det kun p,
som er en pointer.

(Der er noget med, at det ikke er helt lovlig C med 0-størrelses
arrays, men jeg kan ikke huske detaljerne uden videre)

-- 
Regards, Anders                         If a Microsoft product
(address is valid)                      fails, who do you sue?


 
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] *