2

I know that #error directive works at least with GCC and MSVC

 #if !defined(__cplusplus) #error C++ compiler required. #endif 

But is it crossplatform and crosscompiler in general? Is it a part of some standard maybe?

PS. Because even looking at examples given in GCC and MSVC manuals one sees differences. While it works both with quotes or not, it makes a sad feeling, that it might be somehow compiler dependent.

GCC example

#error "Won't work on ..." // quotes here 

MSVC example

#error C++ compiler required. // no qutes 
9
  • I'm not sure there's any harm in asking this given that there doesn't seem to be a duplicate. Granted, the reference was quite easy to find. But SO is aiming to become a comprehensive Q & A repository and in that sense this question is contributory. Commented Jul 28, 2017 at 13:30
  • "Is it a part of some standard maybe?" Yes, both the C and C++ language standards, as a simple find/grep through them would have revealed. Do we really need a canonical thread for every trivial "Can I do X?" type question that people think up? I see what you mean, but surely there needs to be a cutoff point somewhere. Commented Jul 28, 2017 at 13:31
  • 2
    It is standard, but it's not a macro. Commented Jul 28, 2017 at 13:31
  • @underscore_d: Well, there's certainly room for it. And this makes a change from all the reg-ex and UB ++i++ tosh that litters the C and C++ tags. Commented Jul 28, 2017 at 13:32
  • I don't have 'grep' easily accessible in windows. And I think it is not a garbage because in my workflow I would search it first on google and/or stackoverflow. Which means that probably a number of people would do the same. Than I saw that difference in VS and GCC manual. Which made me suspicious. And btw cppreference doesn't provide any peculiarities like quote marks Commented Jul 28, 2017 at 13:38

1 Answer 1

7

Yes it is. It's a standard preprocessor directive in C and C++.

References: http://en.cppreference.com/w/cpp/preprocessor/error http://en.cppreference.com/w/c/preprocessor/error

Sign up to request clarification or add additional context in comments.

4 Comments

Citing a non-authoritative source for a question explicitily asking for a standard is not really a good idea. Why not link the C standard? IIRC, the C++ standard in term references the cpp.
Well, for starters, the question was tagged C and C++ before you removed them: I've now put back. Not sure we should make such changes without consulting the OP.
I removed them for exactly the reasons I mentioned in my comment. How does this affect my first objection?
There's nothing stopping you from linking the C (and C++) standards in an answer. I tend to take en.cppreference.com as a proxy for the standards, and this particular topic lends itself to that.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.