Code::Blocks Forums

User forums => Help => Topic started by: visir on July 09, 2017, 03:21:58 pm

Title: # if _MSC_VER >= 1400
Post by: visir on July 09, 2017, 03:21:58 pm
Just found this in one program

Code
#  if _MSC_VER >= 1400
_sopen_s(&handle, filepath, mod | opt, (dolock ? ((mod == O_RDONLY) ? _SH_DENYRD : _SH_DENYRW) : _SH_DENYNO), _S_IREAD | _S_IWRITE);
#  else
handle = _sopen (filepath, mod | opt, (dolock ? ((mod == O_RDONLY) ? _SH_DENYRD : _SH_DENYRW) : _SH_DENYNO), _S_IREAD | _S_IWRITE);
#  endif

codeblocks highlights the first part, while debugger stops at the second one. The "_MSC_VER >= 1400" seems to mean "visual studio 2005 or older". But I'm actually using msys2. This change has this comment: "fixed all VS2005 deprecated function warnings".

What should I do with this thing, any suggestions?
Title: Re: # if _MSC_VER >= 1400
Post by: oBFusCATed on July 09, 2017, 04:19:21 pm
Disable the editor feature that greys out preprocessor directives...
Title: Re: # if _MSC_VER >= 1400
Post by: visir on July 09, 2017, 04:38:58 pm
That is indeed a suggestion, but...

Let's just chat about something. About, dunno, microsoft, preprocessor.
Title: Re: # if _MSC_VER >= 1400
Post by: oBFusCATed on July 09, 2017, 05:26:16 pm
Chat about what? The editor doesn't know about defines from project/compiler settings, neither it knows about compiler built-in defines.
Until someone implement this, it is best to just disable this feature. And btw this is not the first time some one is complaining about this.
Title: Re: # if _MSC_VER >= 1400
Post by: visir on July 09, 2017, 05:40:21 pm
Hm...

Any way to print out the value of _MSC_VER? Compiler probably defines it in the headers somewhere, I need to find out the exact value and copy it into #defines in project options.
Title: Re: # if _MSC_VER >= 1400
Post by: oBFusCATed on July 09, 2017, 05:49:19 pm
This is not a good idea. Why would you want to do this? This is internal define in the compiler, bad things will happen if there is a mismatch.
Most compilers make it possible to generate the preprocessed source code instead of object files. Search the internet for details how to do this with your compiler
Title: Re: # if _MSC_VER >= 1400
Post by: visir on July 09, 2017, 09:11:58 pm
Okay, it looks like _MSC_VER is undefined for me. And because it's undefined, expressions like #if _MSC_VER >= 1400 are equivalent to #if 0 >= 1400. This is actually in C and C++ standards, according to https://stackoverflow.com/questions/5085392/what-is-the-value-of-an-undefined-constant-used-in-if

Looks like there is a bug in codeblocks, if it thinks that _MSC_VER is undefined, and still thinks that _MSC_VER >= 1400 is true.

Actually whatever, I'll need to delete all those anyway.