Thread: why not void main??

  1. #1
    Registered User
    Join Date
    Jun 2005

    why not void main??

    is it by any means not recommended to use 'void main' even if your program is not returning anything...heard ppl sayin go for 'int main' & put 'return 0' in the end if aint got nethng to return....why so???

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Read the FAQ. Or search the forum.

    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Jun 2005

  4. #4
    Registered User
    Join Date
    Jun 2005
    but didnt get this paragraph:

    "Because the startup routines that call main could be assuming that the return value will be pushed onto the stack. If main() does not do this, then this could lead to stack corruption in the program's exit sequence, and cause it to crash."

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Pretty much what it says.
    The startup routine (not you) call main.
    Therefore, you should really write a function with the prototype they expect to call, not some half-baked lazy approximation.

    I mean, if you think void is acceptable, what about this?
    #include <stdio.h>
    struct dumb { int a[10000]; };
    struct dumb main ( void ) {
      struct dumb result;
      printf( "hello world\n" );
      return result;
    $ gcc -Wall -W -ansi -pedantic  hello.c
    hello.c:3: warning: return type of `main' is not `int'
    $ ./a.out
    hello world
    Segmentation fault
    I mean, there's no difference between being a little bit wrong and being a lot wrong is there?

    > in the end if aint got nethng to return
    Well if simply adding "return 0;" is too difficult for you, try something else.
    I mean, it's nothing compared to the 1000's of lines which go into any decent sized program.

    Tell me, for functions you write, do you happily abuse the calling conventions of those functions as well?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-05-2009, 10:25 AM
  2. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 02:20 PM
  3. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  4. need help with handelling multiple source files
    By DarkMortar in forum C++ Programming
    Replies: 38
    Last Post: 05-26-2006, 10:46 PM
  5. getting a headache
    By sreetvert83 in forum C++ Programming
    Replies: 41
    Last Post: 09-30-2005, 05:20 AM