This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Compiler Research

According to documentation
RealView Compilation Tools Compiler User's Guide (version 3.1)
Compound literals

int y[] = (int []) {1, 2, 3};

--c90 mode

warning #520-D initialization with "(...)" expected for aggregated object
error #70 incomplate type is not allowed
error #29 expected an expression

--c99 mode

warning #520-D initialization with "(...)" expected for aggregated object
error #144 a value of type "int *" cannot be used to initialize an entity of type "int"

it must be compiled ok, but it is not. What's wrong?

Parents
  • You've left off the comment that is in the documentation:

    int y[] = (int []) {1, 2, 3}; // error in strict C99, okay in C99 --gnu
    

    What you are seeing is consistent with the comment. Some things that are illegal in C99 are nonetheless accepted with --c99 --gnu.

    This usage is legal C99:

    int *yp = (int []) {1, 2, 3};
    

    This usage is legal in C90, C99 and C++:

    int y[] = {1, 2, 3};
    

Reply
  • You've left off the comment that is in the documentation:

    int y[] = (int []) {1, 2, 3}; // error in strict C99, okay in C99 --gnu
    

    What you are seeing is consistent with the comment. Some things that are illegal in C99 are nonetheless accepted with --c99 --gnu.

    This usage is legal C99:

    int *yp = (int []) {1, 2, 3};
    

    This usage is legal in C90, C99 and C++:

    int y[] = {1, 2, 3};
    

Children