Ambiguous between syntax and semantic error [closed]

Nothing in the C lexical analysis or grammar distinguishes int from void. The both appear exactly once in the C grammar, as a type-specifier in C 6.7.2 1. Therefore, the only way to distinguish these two samples of code:

void *x[] = { (char *) 0 };


int *x[] = { (char *) 0 };

is by using the meaning of the code, as given by the C standard in constraints and other text. They are in fact distinguished by compilers, as the first is accepted without complaint about the types, but the second results in a complaint about the type of the initializer for the array element. Therefore, this is a semantic error.

Browse More Popular Posts

Leave a Comment