MSVC 2010 vs. XCode 4/gcc-4.2
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: MSVC 2010 vs. XCode 4/gcc-4.2

  1. #1
    Join Date
    Aug 2002
    Posts
    581

    MSVC 2010 vs. XCode 4/gcc-4.2

    Hi, ALL,
    First of all, I apologize if this post does not belong here.

    So, here goes.

    In my project I used to have following code:

    Code:
    class A
    {
    public:
        int GetA() { return m_a; };
    private:
        int m_a;
    };
    
    int main()
    {
         A a;
         int var = a.GetA();
    }
    This code was compiled with MSVC 2010 and everything was OK.
    Later the project evolved and I had to change int to double. Unfortunately, I forgot that in some places I used this function and the code in main() is unchanged and so the code snippet becomes:

    Code:
    class A
    {
    public:
        double GetA() { return m_a; };
    private:
        double m_a;
    };
    
    int main()
    {
         A a;
         int var = a.GetA();
    }
    Now this new code compiled fine in MSVC 2010. There is no error or warning.
    Today I tried to compile this code on XCode 4.2 with gcc-4.2 (lates XCode for Snow Leopard). To my surprise I received a warning about conversion from 32-bit to 64-bit. I can drop the exact warning message here if needed.

    Now both projects are compiled as 32-bit executable in Debug mode.

    Now my question is: why MSVC did not warn me about this? Is this some kind of MSVC extension? Or I just need to increase a warning level for the project, which set as "Level4 (/W4)"?

    Thank you.

  2. #2
    Join Date
    Apr 1999
    Posts
    27,427

    Re: MSVC 2010 vs. XCode 4/gcc-4.2

    Quote Originally Posted by OneEyeMan View Post
    Now my question is: why MSVC did not warn me about this?
    Warnings are not errors.

    Compilers are not mandated to emit warnings if the syntax or usage of the C++ language is perfectly legal. You can probably find warnings that VC gives you that gcc doesn't give you. The only thing a compiler is required to do is to stop compilation on illegal use of the language (and I believe, emit a diagnostic).

    A compiler's "warning feature" is just that -- a feature -- it isn't a requirement. If you want warnings, better to use a lint tool than to rely on what a compiler may or may not offer.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; October 18th, 2013 at 04:24 AM.

  3. #3
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,585

    Re: MSVC 2010 vs. XCode 4/gcc-4.2

    Quote Originally Posted by OneEyeMan View Post
    Code:
    class A
    {
    public:
        double GetA() { return m_a; };
    private:
        double m_a;
    };
    
    int main()
    {
         A a;
         int var = a.GetA();
    }
    Now this new code compiled fine in MSVC 2010. There is no error or warning.
    Today I tried to compile this code on XCode 4.2 with gcc-4.2 (lates XCode for Snow Leopard). To my surprise I received a warning about conversion from 32-bit to 64-bit. I can drop the exact warning message here if needed.
    On my VC 2010 with the IDE default warning level 3 this snippet raises a C4244 warning:

    Code:
    1>c:\[some path]\projects\test11\test11\test11.cpp(12): warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data
    As the warning level is set to 3, this must be a level 3 warning (can be level 3 or 4 depending on context, see MSDN), otherwise I wouldn't have got it. So I suspect you're in fact compiling it at a warning level below 3, or this particular warning has been disabled or raised to level 4 using #pragma warning.

    Actually, this is one of my personal pet warnings , so I was rather surprised when reading your claim to not getting it.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  4. #4
    Join Date
    Aug 2002
    Posts
    581

    Re: MSVC 2010 vs. XCode 4/gcc-4.2

    Eri523,
    I have Microsoft Visual Studio 2010 Professional SP1 and I don't receive any such warning compiling my project from the IDE as well.
    Selecting the project, doing right click and selecting "Properties", then opening "C/C++", I see Warning Level set to be "Level4 (/W4)".

    Any other settings to check?

    Thank you.

  5. #5
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,585

    Re: MSVC 2010 vs. XCode 4/gcc-4.2

    Besides the warning level option from the "C/C++ -> General" options we already discussed, there's a "Disable Specific Warnings" option under "C/C++ -> Advanced". And there's "Additional Options" under "C/C++ -> Command Line" where additional command line switches can be specified. Note that all these options not only can be set project-wide, but also be overridden per source file.

    Then there's the #pragma warning we already discussed. I, personally, use that to specifically disable C4244 for specific sections of my code that throw a lot of them. However, I rarely actually see the need to do so, and then only for parts of the source file I'm not currently working on. Hence the #pragma instead of simply setting the respective option. Yes, of course, I could eliminate all the C4244 warnings by proper casting, but if I would do that the proper C++ way, that would really reduce code readability.

    However, all of the above things would be practically impossible to overlook in a tiny demo project built around your snippet, and probably wouldn't be too easy to overlook in a production size project as well, except perhaps the #pragma in parts of the project code you didn't write yourself.

    Finally, there's the CL environment variable from which the compiler reads additional command line switches, and of course warning-related options can be specified there too. That's the most tricky place I know of to hide such things...
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  6. #6
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,382

    Re: MSVC 2010 vs. XCode 4/gcc-4.2

    Isn't this bascially the same post by the same OP as
    http://forums.codeguru.com/showthrea...87#post2132987
    in another forum?
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  7. #7
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,585

    Re: MSVC 2010 vs. XCode 4/gcc-4.2

    Quote Originally Posted by 2kaud View Post
    Isn't this bascially the same post by the same OP as
    http://forums.codeguru.com/showthrea...87#post2132987
    in another forum?
    Yes, it's the same subject, but I'd say the aspect under which it is discussed is different: Coding alternatives over there, reasons why VC2010 doesn't issue the C4244 warning here.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  8. #8
    Join Date
    Aug 2002
    Posts
    581

    Re: MSVC 2010 vs. XCode 4/gcc-4.2

    Hi,
    Quote Originally Posted by Eri523 View Post
    Besides the warning level option from the "C/C++ -> General" options we already discussed, there's a "Disable Specific Warnings" option under "C/C++ -> Advanced". And there's "Additional Options" under "C/C++ -> Command Line" where additional command line switches can be specified. Note that all these options not only can be set project-wide, but also be overridden per source file.
    Well, "Disable Specific Warnings" option is empty. And "Additional Options" under "Command Line" is also empty.

    Quote Originally Posted by Eri523 View Post
    Then there's the #pragma warning we already discussed. I, personally, use that to specifically disable C4244 for specific sections of my code that throw a lot of them. However, I rarely actually see the need to do so, and then only for parts of the source file I'm not currently working on. Hence the #pragma instead of simply setting the respective option. Yes, of course, I could eliminate all the C4244 warnings by proper casting, but if I would do that the proper C++ way, that would really reduce code readability.
    There is no "#pragma"'s in that file. I don't like using that feature.

    Quote Originally Posted by Eri523 View Post
    However, all of the above things would be practically impossible to overlook in a tiny demo project built around your snippet, and probably wouldn't be too easy to overlook in a production size project as well, except perhaps the #pragma in parts of the project code you didn't write yourself.

    Finally, there's the CL environment variable from which the compiler reads additional command line switches, and of course warning-related options can be specified there too. That's the most tricky place I know of to hide such things...
    Well I'm compiling thru the IDE. So, no CL.

    Any other idea?

    Thank you.

  9. #9
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,585

    Re: MSVC 2010 vs. XCode 4/gcc-4.2

    Quote Originally Posted by OneEyeMan View Post
    Well I'm compiling thru the IDE. So, no CL.
    I specifically tested that using the IDE. Not invoking CL over the command prompt doesn't save you from the influence of environment variables. After all, it's CL that gets invoked by the IDE.

    Any other idea?
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center