3 ms·
The 1999 ISO C standard dropped the "implicit int" rule, so this: main(argc, argv) char *argv[]; { /* ... */ } is illegal (strictly sp
by _kst_ 13y ago
The 1999 ISO C standard dropped the "implicit int" rule, so this:
main(argc, argv)
char *argv[];
{
/* ... */
}
is illegal (strictly speaking, it's a "constraint violation"). Note that it's
char *argv[]
not
int argv[]
But this:
int main(argc, argv)
int argc;
char *argv[];
{
/* ... */
}
is still perfectly valid.
As for this:
int main(int argc, unsigned long long argv[]) {
char *firstarg = (void *)(argv[1]);
printf("%s", firstarg);
}
it's not a constraint violation, but its behavior is undefined (unless your compiler specifically supports and documents that particular form as an extension).
- rmrfrmrf 13y agoWe're talking about the code from the actual source files, not the standard. Look here (lines 22 and 23): https://github.com/mortdeus/legacy-cc/blob/master/prestruct/c00.c https://github.com/mortdeus/legacy-cc/blob/master/prestruct/... The compiler code states int argv[], not char argv[] (I assumed this is why the OP asked for clarification in the first place, since char argv[] is much more common). You're right, in theory this is undefined behavior, but in practice on a 32-bit system, sizeof(int) will almost always be equal to sizeof(void *). I was just demonstrating how one could recreate the code in the compiler while on a 64-bit architecture.