Using the word main as an identifier
Can we use main as an identifier?
If yes what ma开发者_高级运维y be the scenarios?
Why not, provided you don't use it in the way main()
is used, that is, as a function.
/* Error -- > */ int main() { return 1; } // Redefinition of main()
struct main{}; // ok
int main = 0 ; // error
int main(void)
{
int main=0; // But has to be local.
goto main;
printf("Hello");
main:
printf("World");
}
Remember main
is NOT
a Keyword. But i guess we have not ran out of words, so why use it?
Technically? As a static
or auto
variable name inside any function, or as a static
file-scope variable in any file other than the one containing main()
. It might also work as a struct
or union
tag, or as a typedef
anywhere but the file containing main()
.
Practically? It's a good way to confuse yourself when you come back to the program a year later and wonder what idiot thought that was a good idea. :)
Ok folks, here's the $64,000 question: why would you want to do this? Planning to enter the obfuscated C contest, perhaps? Some unique approach to writing a quine? A test case for a lint-like program? It's certainly not something you'd want to do in a real program.
精彩评论