Thread: why do we 'int main()'?

  1. #16
    Registered User
    Join Date
    Aug 2001
    Posts
    247

    Thumbs up

    Thanks sayeh, for the highly informative input...generally I would use int main ( ), but for the standard being set by my course supplier. I have been docked marks from assignments when I have not used void main ( ). So in the mean time I shall continue to use void main (). If I am fortunate enough to gain employment as a programmer, then I shall follow suit along with the department recommendations. Which will probably be int main ().

    Salem, I read most of your posts on here, which I find highly informative. I have no doubt you have aided many of us on here on numerous occasions. I do not disagree with you. My main problem is that my course supplier stipulates the use of void main (); so if I post code that includes this then you know that I am conforming to a standard set not by myself. When I see something that doesnot conform to what have been taught then I have to find out why? Being a would be programmer, then this is not a bad thing, even if I am wrong I will probably say I am right until I find out categorically that this is not the case. Better this way than just accepting what people say. I have sent my tutor the web page, and await his reply with anticipation. Unfortunately before sayeh posted. I shall probably send that in reply to his reply.
    hoping to be certified (programming in c)
    here's the news - I'm officially certified.

  2. #17
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    #ifndef NONCOURSEUSE
    void main( )
    #else
    int main( )
    #endif
    
    
    #ifdef NONCOURSEUSE
       return 0;
    #endif

    Then you can just quote Ric Flair to your instructor:
    "You don't have to like it, but learn to love it! Because it's the best thing going! WHOOOOOOOOOOOOOOOO!"
    Quzah.

  3. #18
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    http://www.cprogramming.com/cboard/s...&threadid=3939
    I said
    > Unbelievably, I've heard of one such teacher who took marks away for using int main - sheesh!

    Make that two.

    The case for the prosecution rests m'lud.
    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.

  4. #19
    Registered User
    Join Date
    Sep 2001
    Posts
    412
    BTW, to whomever said it "uses more memory" to do a return with a value:

    A return 0 generates TWO BYTES more code -- it adds the opcode 33 C0 (xor eax,eax). A return of a nonzero takes five bytes more -- for example, return 1 adds the opcode B8 01 00 00 00 (mov eax, 00000001).

    Neither code costs much time (both moves w/ immediate operands and XORs can be executed in one instruction cycle) and neither takes any appreciable amount of space.

  5. #20
    Registered User
    Join Date
    Aug 2001
    Posts
    16
    (igor voice) Must save... Must SAVE memory for the boss...(inane laughter)...

    Although I currently use void main, I will change if I run into a problem. I would rather people not use my programs, so I will be as unhelpful to them as possible. Not that I've ever finished a program either, but I will within a week. My first game, and its 3k lines long. That is without the text from the text adventure part...
    By the way, any chance there is a dbz fan reading my post? I would like to hear from you...
    "Practice means good, Perfect Practice means Perfect"

  6. #21
    A Banana Yoshi's Avatar
    Join Date
    Oct 2001
    Posts
    859

    I use main()

    not int main() nor void main(), I use main()
    Yoshi

  7. #22
    aurė entuluva! mithrandir's Avatar
    Join Date
    Aug 2001
    Posts
    1,209
    I follow the standard and always use int main(void)

  8. #23
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    > I follow the standard and always use int main(void)

    I bet that makes processing command line arguments difficult, eh?

    Quzah.

  9. #24
    Registered User jasrajva's Avatar
    Join Date
    Oct 2001
    Posts
    99
    Engineer said
    not int main() nor void main(), I use main()
    most compilers i know have the default return type as int so

    main() would mean the same as int main()
    jv

  10. #25
    .
    Join Date
    Aug 2001
    Posts
    598
    >I have used DevC++, which doesnot allow void main ()...so I had to change my project work after pasting to print format from compiler. I now use TurboC++ and use void main (void)...although I could use int main ()..but then I would have to change the code and remove return 0; before posting. <

    Did you ever stop and wonder why Dev C++ does not allow void main(void).



    Nope, cant delcare winmain void.
    To Err Is To Be Human. To Game Is Divine!"

  11. #26
    free(me);
    Join Date
    Oct 2001
    Location
    Santo Domingo, DN, Dominican Republic
    Posts
    98

    ...

    Code:
    int main(void) /* since i'm not accepting any command-line args */
    {
    /* code */
    return 0;
    }
    I'm DragonBall (Z) Fan. I also enjoy most anime/manga i can get my hands on.

    adios,
    biterman.
    Do you know how contemptous they are of you?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Drawing Program
    By Max_Payne in forum C++ Programming
    Replies: 21
    Last Post: 12-21-2007, 05:34 PM
  2. Debug Error Really Quick Question
    By GCNDoug in forum C Programming
    Replies: 1
    Last Post: 04-23-2007, 12:05 PM
  3. Switch/case Problems (long code in post)
    By Wraithan in forum C++ Programming
    Replies: 2
    Last Post: 12-01-2005, 06:40 PM
  4. getting a headache
    By sreetvert83 in forum C++ Programming
    Replies: 41
    Last Post: 09-30-2005, 05:20 AM
  5. Quack! It doesn't work! >.<
    By *Michelle* in forum C++ Programming
    Replies: 8
    Last Post: 03-02-2003, 12:26 AM