Re: Segmentation fault!




"Chris Torek" <nospam@xxxxxxxxx> wrote in message
news:dslkac02uq3@xxxxxxxxxxxxxxxxxxxx
Rod Pemberton wrote:
Wouldn't kids be better defined like so:
struct _node_t *(kids[]);

This is a C99 feature: a structure that ends with a member of type
"array of T" (for some valid data type T), with no size, creates
a struct type with a "flexible array member". While C99-conformant
compilers are becoming more common, in my opinion they are not yet
common enough to recommend regular use of C99 features. Still,
this is a reasonable thing to do if you have C99 compilers. This
gives:

Just an FYI (for others, since Chris is probably familiar), this technique
existed prior to C99. It was called the C90 'struct hack' and works with
almost all C compilers. When standardized in C99, it became known as
variable length arrays.

If you've never heard of the C90 'struct hack', read #28 here:
http://home.tiscalinet.ch/t_wolf/tw/c/c9x_changes.html


Rod Pemberton


.



Relevant Pages

  • Re: Memory alignment
    ... Why would you want to declare a 1 char array to store 2 anyway? ... In C99, a modified version of the concept ... Using offsetofrather than sizeof() makes a difference for the C90 ... because the size of the struct includes enough room for one ...
    (comp.lang.c)
  • Re: Flexible arrays getting in the way?
    ... and compiled it with C99 standard. ... I don't know the details of such standard but, apparently, the ... compiler thinks that I'm trying to define a struct with a "flexible ... gets rejected as "invalid use of flexible array member". ...
    (comp.lang.c)
  • Re: C Expression Parsing in Forth?
    ... > issues if done with integer math. ... C99 has complex so it would probably be more ... natural to point to two complex's, or even to one array ... Alternatively it is possible to _return_ a struct ...
    (comp.lang.forth)
  • Re: Linguistics and such
    ... There's no special term for an object of a struct type, ... In C90, both declarations are illegal. ... In C99, both declarations are legal, and they both create VLAs ... constant expression; Ci is merely a read-only object. ...
    (comp.lang.c)
  • Re: Accessing array elements within a structure
    ... struct test example; ... what makes you think this is a C99 implementation? ... some more indication that it will actually work. ...
    (comp.lang.c)