test.c
int main () {
void a;
return 0;
}
I use gcc to compile but it gives me an error:
error: variable or field ‘a’ declared void
From what I read here,
I thought I can declare void variable without problem.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As your link states:
This means that although syntactically correct, a
voiddeclaration is not useful to anything, this is why GCC could consider it an error. Even if it would compile, you won’t be able to do anything with the variable, so I guess your question is just related to testing this behavior.In fact
voidis useful just when we’re talking about pointers (void*) since it allows you to declare a generic pointer without specifying the type.