Page 3 of 3 FirstFirst 123
Results 21 to 26 of 26
  1. #21
    Join Date
    Feb 2005
    Location
    Bellevue, WA
    Posts
    3,251
    You can disable language extensions: Configuration Properties > C/C++ > Disable Language Extensions: Yes

    This gets you the warning for void main().

    Then turn on Warnings as Errors.

    That's as good as I know how to get it in VS.

    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." ~Rich Cook

  2. #22
    Join Date
    Jul 2006
    Location
    San Diego, CA, USA
    Posts
    897
    Quote Originally Posted by ComicSansMS View Post
    There is a standards-mode? I've never heard of that, is that an official feature?

    Personally I find it very healthy to regularly test code on different compilers. After you do that for a while, you'll get a pretty good feeling of what's part of ISO C++ and what isn't. For example, I like to test any platform-independent code I write at least on Visual Studio, GCC and Clang (which finally understands Lambdas now), all cranked up to high warning levels. You'd be surprised how many errors get caught by just doing that...
    That got me thinking as well too. I know you can turn off MS Language Extensions (/Za) but I guess I hadn't tried to force it to follow ANSI C++ standards purely. I use Warning Level 4 (think that's the highest) too.

    Microsoft - "The /Za compiler option emits an error for language constructs that are not compatible with either ANSI C or ANSI C++"

    Personally I find it very healthy to regularly test code on different compilers. After you do that for a while, you'll get a pretty good feeling of what's part of ISO C++ and what isn't.
    Agreed. No arguments there. In my job, however, following the standards to the N-th degree isn't a requirement so we primarily use Visual Studio and its compiler. The Linux side of the house uses GCC and Eclipse for the IDE.


    @owensd
    Just because a program "works", doesn't mean it's correct.
    I will concede to your point because frankly I do agree with you. I just saw "you can't" and felt compelled to respond with "oh, yes you can". Does it make it right or even safe, no. I understand the caller of main() expects a return value and it can lead to stack problems. So here goes, it's wrong to use void main(), don't do it... ever.


    EDIT: You beat me to posting owensd, on the /Za compiler switch.
    EDIT2 - Again was curious so with that switch 'on' recompiling gave this warning which was an error with "Warnings as Errors" turned on.

    Warning 2 warning C4326: return type of 'main' should be 'int' instead of 'void' c:\dev\other\area51_other\test\test.cpp 2 1 test
    Last edited by smjones; 03-07-2012 at 04:32 PM.
    Code Fearlessly!

  3. #23
    Join Date
    Feb 2005
    Location
    Bellevue, WA
    Posts
    3,251
    Quote Originally Posted by smjones View Post
    EDIT2 - Again was curious so with that switch 'on' recompiling gave this warning which was an error with "Warnings as Errors" turned on.
    That's because it's a Microsoft language extension that is allowing that. Disabling those extensions gives you the warnings that you are doing something potentially bad.

    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." ~Rich Cook

  4. #24
    Join Date
    Jun 2003
    Location
    Trier, Germany
    Posts
    1,350
    Thanks guys, I guess I'll add /Za to my standard setup.

    Quote Originally Posted by smjones View Post
    I use Warning Level 4 (think that's the highest) too.
    Technically, there is /Wall with VS2010 and up, but that one is so picky it doesn't even compile the standard library headers without complaining all over. Not recommended.

  5. #25
    Join Date
    Jul 2006
    Location
    San Diego, CA, USA
    Posts
    897
    This was enlightening for sure.
    Code Fearlessly!

  6. #26
    Join Date
    Feb 2005
    Location
    Bellevue, WA
    Posts
    3,251
    Quote Originally Posted by ComicSansMS View Post
    Technically, there is /Wall with VS2010 and up, but that one is so picky it doesn't even compile the standard library headers without complaining all over. Not recommended.
    Yeah... and I don't know how to ignore those from outside of your code. So annoying.

    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." ~Rich Cook

Page 3 of 3 FirstFirst 123

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •