News for hackers. Stuff that matters.
Re:Main is usually a function, so when is it not? (2015) by pjc50 on Sunday September 10, 2017 @10:15AM (#15212293)
Someone should tell the gcc maintainers then.

    int main()
    {
        int a = 12;
    }

    $ gcc maintest.c
    $ ./a.out
    $ echo $?
    148
Re:Main is usually a function, so when is it not? (2015) by TazeTSchnitzel on Sunday September 10, 2017 @10:18AM (#15212297)

  $ cat test.c
  int main(void) {int a = 12;}
  $ gcc-6 test.c -o test --std=c89; ./test; echo $?
  162
  $ gcc-6 test.c -o test --std=c99; ./test; echo $?
  0
Must be a C99 thing.
Re:Main is usually a function, so when is it not? (2015) by albinofrenchy on Sunday September 10, 2017 @12:01PM (#15212757)
This isn't that conclusive of a test -- uninitialized memory is 0 relatively often.
Re:Main is usually a function, so when is it not? (2015) by clarry on Sunday September 10, 2017 @01:55PM (#15213356)
Re:Main is usually a function, so when is it not? (2015) by pjscott on Sunday September 10, 2017 @06:00PM (#15214517)
Okay, that is conclusive. (And I'm pleasantly surprised by how readable GCC's source code is.)
Re:Main is usually a function, so when is it not? (2015) by kaushiks on Sunday September 10, 2017 @04:12PM (#15214093)
This has nothing to do with memory. The x86_64 ABI returns values from functions in the RAX register.
Re:Main is usually a function, so when is it not? (2015) by albinofrenchy on Sunday September 10, 2017 @04:45PM (#15214243)
Sure; same point applies though -- just because 0 happens to be in RAX doesn't mean it's defined behavior.