Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
recently I started to view some legacy code and frequently see this state in header files:

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


I missed some part of the history of Visual C++ or Visual Studio.
I think I can safely replace this macro statement with:
#pragma once


can any gurus share the origin of this kind of macro statement?

What I have tried:

I removed #if statement and have no issue.
Posted
Updated 6-Oct-20 8:49am

1 solution

_MSC_VER is a Microsoft-specific predefined macro. Versions of the Microsoft C/C++ compiler earlier than 10 (Visual Studio 2010, IIRC) didn't support this pragma, and would emit a warning message "unrecognized pragma", or something similar. The only purpose of the macro guard is to avoid this message.

If you are targeting later versions of Microsoft C/C++, you can remove the macro guard.
 
Share this answer
 
Comments
Southmountain 6-Oct-20 22:21pm    
thank you very much!
BongoVR 7-Oct-20 1:13am    
According to https://dev.to/yumetodo/list-of-mscver-and-mscfullver-8nd, _MSC_VER = 1000 refers to the first 32 bit compiler from Microsoft (Visual Studio 4.0) from the mid-1990s. So, it is REALLY safe to remove the macro.
Southmountain 7-Oct-20 18:47pm    
thank you for the link!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900