Products
and Services Support
and Docs Training Partner Programs About Red
Hat
  download storecart
red hat logo
redhat.comredhat network

Red Hat Documentation

Arrays of Length Zero Contents|Index|Previous|Next
 Arrays of length zero  

Zero-length arrays are allowed in GNU C. They are very useful as the last element of a structure which is really a header for a variable-length object.
    struct line { 
       int length; 
       char contents[0]; 
    }; 
    { 
       struct line *thisline = (struct line *) 
          malloc (sizeof (struct line) + this_length); 
       thisline->length = this_length; 
    }
In standard C, you would have to give contents a length of 1, which means either you waste space or complicate the argument to malloc.

 

 


 
© 2001 Red Hat, Inc. All rights reserved.
About Red Hat  :  Legal statement  :  Privacy statement  :  Y2K statement  :  Contact Red Hat