Solved

#if _MSC_VER > 1000

Posted on 2001-09-07
7
3,299 Views
Last Modified: 2013-11-20
what exactly is this statement used for
#if _MSC_VER > 1000
#pragma once
#endif
0
Comment
Question by:mjh2
  • 4
  • 2
7 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 6464814
This statement is used to differentiate between different compiler versions. From the docs:

_MSC_VER

Defines the compiler version. Defined as 1200 for Microsoft Visual C++ 6.0. Always defined.


This means - in your example - that the code enclosed will only be 'seen' by MS compilers that have an internal version stamp > 1000, as '#pragma once' is probably not implemented by earlier versions. 'once' itself means:

#pragma once

Specifies that the file, in which the pragma resides, will be included (opened) only once by the compiler in a build. A common use for this pragma is the following:

//header.h
#pragma once
// Your C or C++ code would follow:



0
 
LVL 49

Accepted Solution

by:
DanRollins earned 300 total points
ID: 6465898
I might add that

   #pragma once

can be used as a replacement for the common practice of placing #ifdef like this at the top and bottom of a header file:

#if !defined(DLGPGSVRPARSING_H)
#define DLGPGSVRPARSING_H
... entire source file here ...
#endif

Therefore, if you expect to always use VC++ 6.0 or later, you could manually replace this ugly baggage at the top of your .h files:
---==-=--==--=-=-=-=-=-==--=-=
#if !defined(AFX_DLGPGSVRPARSING_H__B25B9214_2E48_46EB_A306_F750626C5256__INCLUDED_)
#define AFX_DLGPGSVRPARSING_H__B25B9214_2E48_46EB_A306_F750626C5256__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
---==-=--==--=-=-=-=-=-==--=-=
with this one, clean line:

#pragma once

Just remember to also delete the #endif line tha tlooks like this from the bottom of the file:
---==-=--==--=-=-=-=-=-==--=-=
#endif // !defined(AFX_DLGPGSVRPARSING_H__B25B9214_2E48_46EB_A306_F750626C5256__INCLUDED_)
---==-=--==--=-=-=-=-=-==--=-=

-- Dan
0
 
LVL 86

Expert Comment

by:jkr
ID: 6466004
>>I might add that '#pragma once'can be used as a
>>replacement for the common practice of placing #ifdef
>>like this at the top and bottom of a header file..

You're right, but I would not recommend abandoning that practise - there are more compilers out than just VC++, even though MFC is focused a little on that compiler implementation (even though I remember that my first encounter with MFC was with Watcom 10.0)

0
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.

 
LVL 86

Expert Comment

by:jkr
ID: 6468695
???
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6469592
hi mjh2,
Thanks for accepting my comment as an answer.  However, in this case, all I did was add a note to an already correct and complete answer that had been given by jkr.

The 'B' grade that you awarded to me, should instead be awarded to jkr.

hi jkr,
sorry.  I had no intention of 'poaching'.

-- Dan
0
 
LVL 86

Expert Comment

by:jkr
ID: 6472005
>>I had no intention of 'poaching'

I know - you wrote 'I might add that...'. Well, let's see what mjh22 has to say...
0
 

Author Comment

by:mjh2
ID: 6477437
I am sorry jkr.. DanRollins answer gave me more insight on what the code is used for. You gave the definition that anyone can find on Microsoft's web page.
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Add content to output file 4 67
VBA "SendKeys" Syntax for Multiple Keystrokes 7 117
sum28 challenge 31 115
How do I get Window Title of all opened process? 4 14
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

829 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