I tried several variations on
main() return;
or
main() if();
and obtained different errors, the most peculiar of which was
/usr/lib/gcc/i686-linux-gnu/4.4.5/../../../../lib/crt1.o: In function `_start': (.text+0x18): undefined reference to `main' collect2: ld returned 1 exit status
While it's uncommon for a program to require only one statement, why does main() make it a requirement to have braces?
Could someone explain why the error was so peculiar when compiling just int main();?
Because you are defining a function named main() and a function definition is basically a function declaration (the int main() part) followed by a compound statement (the { /* ... */ } part) (you could also use a function try block, but those are very rarely used and still require braces).
You can't define any function without braces.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With