?
Solved

_MSC_VER and VCPP6

Posted on 2007-10-16
3
Medium Priority
?
1,703 Views
Last Modified: 2008-07-10
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?
0
Comment
Question by:Rothbard
3 Comments
 
LVL 4

Assisted Solution

by:Ichijo
Ichijo earned 80 total points
ID: 20087182
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
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 120 total points
ID: 20087584
>>>> 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
 

Author Comment

by:Rothbard
ID: 20092079
Thank you very much for your replies!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question