_MSC_VER and VCPP6

A program for random number generation which I am looking at includes the following bit:

#include <cmath>
//
// the basic math functions should be in namespace std
// but aren't in VCPP6
#if !defined(_MSC_VER)
using namespace std;
#endif

What is _MSC_VER? Why is this bit of code necessary?
RothbardAsked:
Who is Participating?
 
itsmeandnobodyelseCommented:
>>>> Why is this bit of code necessary?
the <cmath> of VC6 was

---------------------------------------------
// cmath standard header

#if     _MSC_VER > 1000
#pragma once
#endif

#ifndef _CMATH_
#define _CMATH_
#ifdef _STD_USING
 #undef _STD_USING
 #include <math.h>
 #define _STD_USING
#else
 #include <math.h>
#endif /* _STD_USING */
#endif /* _CMATH_ */

/*
 * Copyright (c) 1994 by P.J. Plauger.  ALL RIGHTS RESERVED.
 * Consult your license regarding permissions and restrictions.
 */
----------------------------------------------

You see that <cmath> included (old) math.h in every case, but if _STD_USING was defined by a previous include file, it makes an #undef _STD_USING prior to including math.h.

That means math.h shouldn't be included with _STD_USING defined in neither case.

Actually, that still doesn't make much sense in VC6 as <math.h> has no further include and doesn't care for _STD_USING. Same applies for some of the other STL headers that were defined similar. So it seems to me that it was a 'option' rather than a feature. You must know that VC6 was released 1998 a little *before* C++ standard and STL. Nevertheless it has a STL included which redefines some of the symbols defined in the old headers (with extension .h). If not defining 'std' as the default namespace, sources including old headers where redefined symbols were used would not compile as the std:: prefix was missing. As far as I remember that part was incompatible in VC6, i. e. we had to add the 'using namespace std;'  to some sources when compiling them with VC8 though they were compiling without problems in VC6.

I assume the reason for your codepart was similar. It didn't compile with another compiler because of the missing std:: and so the developer added the 'using namespace std;' in case it was not VC compiler.

Note, the clause 'using namespace std;' shouldn't be used in header files cause they wouldn't prevent from using alternative template classes by simply changing the default namespace. Also conflicts because of using names which were class or function names in STL may arise if the using clause was switched on by a header that cannot be omitted.

So, I would remove that sequence in the header you posted.

Regards, Alex
0
 
IchijoCommented:
If _MSC_VER is defined, you're compiling under Microsoft Visual C++. More precisely, for Visual C++ 6.0, _MSC_VER will be defined as 1200. See: http://predef.sourceforge.net/precomp.html

But the #if and #endif really aren't necessary. It won't hurt to compile the "using namespace std;" line in Visual C++ 6.0, even if the math functions aren't in the std namespace.
0
 
RothbardAuthor Commented:
Thank you very much for your replies!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.