Thread: Any Idae .....?

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    7

    Any Idae .....?

    Hello all,

    Why does void main(void) generate a warning message on some compilers (for example the GNU compiler) whereas it works fine for compilers from some other vendors (e.g. Borland’s Turbo C/C++ Compiler). Is there any compiler option available in the compiler to turn this message off?

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    You should't turn it off, instead use int main
    http://faq.cprogramming.com/cgi-bin/...&id=1043284376

    You should prefer the compiler that gives you more warnings over the compiler that silently compiles the wrong code
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > Is there any compiler option available in the compiler to turn this message off?
    Yes, do it properly and say
    int main

    Problem solved.
    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. #4
    Registered User
    Join Date
    Jan 2007
    Posts
    7
    No one gave me a good explanation I asked about why not about what should I do?

  5. #5
    Registered User
    Join Date
    Jun 2004
    Posts
    201
    because C has a standard that defines that main returns int and not void.
    If a compiler happens to accept void as return type its coincidence, so this code will compile on some compilers and not on others. Therefore some compilers choose to accept void but give a warning that this is crappy and you should turn this into int so it will compiler on *all* compilers

  6. #6
    Registered User
    Join Date
    Jan 2007
    Posts
    7
    Good,

    But how I can turn this warning message off from compilers such as Dev-C++

  7. #7
    Registered User
    Join Date
    Jun 2004
    Posts
    201
    Quote Originally Posted by alalam5
    Good,

    But how I can turn this warning message off from compilers such as Dev-C++
    by typing int main(void)

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > No one gave me a good explanation I asked about why not about what should I do?
    So you didn't click on the FAQ link posted by Vart then?

    > But how I can turn this warning message off from compilers such as Dev-C++
    By learning how to do it properly and declaring int main

    EVERY single compiler will do something crappy with respect to the standard at some point (like not warning you about void main). The only defence in your programming is to make sure your code is ANSI-C and not whatever your current compiler will let you get away with.
    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.

  9. #9
    Registered User
    Join Date
    Nov 2006
    Posts
    65
    whats so hard about typing "int main()"? You sound like once of those half c++ converts who has to litter everything up and fight tooth and nail for your c++ ways. Follow the standard that way when you write in linux and want it to work in your dual booted windows (with Grub or bootcamp). To answer your question about the GNU complier why dont you post that in the "Linux Programming" section, but again it would be illogical to turn of a warning that keep you up with standard. If you where wondering the reason why you dont have to place void main() is because some where or some how in ANSI its set to auto place the void if need so just chill homeboy
    You rant and rave about it, but at the end of the day, it doesn't matter if people use it as long as you don't see.
    People are free to read the arguments, but if the only way for you to discover gravity is by jumping off a cliff, then that is what you're going to have to experience for yourself.
    Eventually, this "fast and loose" approach of yours will bite you one too many times, then you'll figure out the correct way to do things. - Salem

  10. #10
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    All you need to know is right here

Popular pages Recent additions subscribe to a feed