Flexible array members of structures

To be compatible with GNU C/C++, the XL C/C++ compiler extends Standard C and C++, to ease the restrictions on flexible array members and allow the following situations:
  • Structures containing flexible array members can be members of other structures.
  • C onlyFlexible array members can be statically initialized only if either of the following two conditions is true:
    • The flexible array member is the last member of the structure, for example:
      struct f { 
        int a;
        int b[];
      } f1 = {1,{1,2,3}}; // Fine.
      
      struct a {    
        int b;
        int c[];
        int d[];
      } e = { 1,{1,2},3}; // Error, c is not the last member
                          // of structure a.
    • Flexible array members are contained in the outermost structure of nested structures. Members of inner structures cannot be statically initialized, for example:
      struct b {
        int c;
        int d[]; 
      }; 
      
      struct c { 
        struct b f;
        int g[]; 
      } h ={{1,{1,2}},{1,2}}; // Error, member d of structure b is
                              // in the inner nested structure.
    C only


Voice your opinion on getting help information Ask IBM compiler experts a technical question in the IBM XL compilers forum Reach out to us