6

I'm using Visual Studio 2010 Express. When I use certain variable names, like "near, "far", "IN", "OUT", I can't compile: I get syntax errors located after the variable name used. Example:

z = 1.0/(far - near);

Error:

error C2059: syntax error : ')'

How can I disable this "feature"?

0

1 Answer 1

12

far and near were built-in compiler keywords back in the 16-bit days. They no longer exist and they no longer have any meaning, but they're still defined as macros in the Windows headers for backwards compatibility reasons.

If you don't want them, just undefine them (or don't include the Windows headers):

#undef far
#undef near
5
  • Thanks, it works. Is there an option to turn off all such keywords (that is all not being a part of c++ standard)? Jan 20, 2012 at 22:21
  • 1
    @user1161552: Yes, remove the line that says #include <windows.h> from your code. They're not keywords, they're macros defined in the Windows headers. Jan 20, 2012 at 22:22
  • 1
    Just came across your answer and want to point out, that this would have been a perfect example for what the implementation reserved namespace (names beginning with two underscores) is meant for. Microsoft is to blame here for not keeping to that namespace.
    – datenwolf
    Nov 29, 2014 at 14:10
  • 1
    @datenwolf: except that I'm pretty sure that implementation reserved namespace didn't exist yet when those keywords were originally introduced. :-) (And they were removed from Visual Studio ages ago.) Sep 16, 2016 at 0:34
  • @datenwolf Implementation reserved namespaces don't help you when you want to preserve backwards compatibility with code that didn't use them. This dates back to before anyone cared about standards (and most of those standards didn't exist in the first place, and people would look at you funny for trying to force something like prefixing keywords with two underscores, especially when identifiers were limited to 6 or 8 characters by many compilers).
    – Luaan
    Sep 16, 2016 at 7:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.