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.
Re: MSVC 2010 vs. XCode 4/gcc-4.2
Quote:
Originally Posted by
OneEyeMan
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
Re: MSVC 2010 vs. XCode 4/gcc-4.2
Quote:
Originally Posted by
OneEyeMan
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.
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.
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... :)
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?
Re: MSVC 2010 vs. XCode 4/gcc-4.2
Quote:
Originally Posted by
2kaud
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.
Re: MSVC 2010 vs. XCode 4/gcc-4.2
Hi,
Quote:
Originally Posted by
Eri523
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
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
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.
Re: MSVC 2010 vs. XCode 4/gcc-4.2
Quote:
Originally Posted by
OneEyeMan
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.