92

me:
#include<stdio.h>
main() {
printf("Hello World");
}

compiller:

Comments
  • 8
    error: C++ requires a type specifier for all declarations
    main() {
    ^
    1 error generated.
    Compiler exited with result code 1
  • 2
    @alyx Also: return 0;
  • 0
    Error: not all code paths return a value.
  • 0
    Ok tried it a little. Actually this shit works. Not sure though what exactly the compiler is doing.
    Using no return type compiles, using void works in gcc but g++ says, main() must return int.
  • 1
    World: Fuck you
  • 0
    @Forside Man do you know C? Offcourse it works through a C compiler.
  • 3
    @Forside main(), even when declared as "int main()" is exempt from having to return a value, and will default to returning zero if no return value is given (since C99).
  • 0
    @alyx That's why C++ has savagery in it.
  • 0
    @Codebeard @alyx I have never seen anyone doing this and know C for punishing you for every little mistake, so I never even thought about trying this. Also I'm a very careful developer and always code as detailed as possible, so letting this out feels like peanutbutter without peanuts to me.
  • 1
    @Forside I should've picked up from stdio.h (as opposed to cstdio) that OP was writing C, not C++. I had no idea that C allows you to omit the type specifier on main(). I guess we've both learned something from this interaction :)
  • 1
    @alyx Well, noone stops you from using stdio.h in C++ as the compiler doesn't even give out a warning.
  • 0
    @Forside You were probably writing more C++ than C. I know, you can pick up some bad practices in C++ when C is concerned.
  • 0
    @Codebeard True. Started with C++ and later had to deal with C when writing for Arduino and Microchip. What I found most confusing, is that it's bad practice in C to cast malloc while it's impossible in C++ not to cast.
Add Comment