3

Why is it that although all other standard C++ macros are prefixed and suffixed by a double underscore, that __cplusplus does not follow suit?

I've looked everywhere I can think of to no success.

  • 4
    I don't see why this is being voted to close - seems like a perfectly good question to me. I've always wondered about it. –  Feb 12 '19 at 21:59
  • 2
    FWIW [cppreference](https://en.cppreference.com/w/cpp/preprocessor/replace) lists a bunch of macros defined in lower case – Tas Feb 12 '19 at 22:07

2 Answers2

0

According to this, cfront (the original C++ compiler) used c_plusplus instead of __cplusplus.

The decision to use c_plusplus seems to be arbitrary (and it ignores the "reserved identifiers" convention, if it existed at that time at all).

I assume __cplusplus was later chosen to make the identifier reserved, while minimizing the difference compared to the original macro name. .


all other standard C++ macros being both all uppercase and prefixed and suffixed by a double underscore

As noted in comments, not all of them are. In the recent years, the commitette seemed to favor lowercase names instead (when adding __has_include and __cpp_* feature test macros).

HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207
-2

This should be of no concern to you. Any name beginning with __ (double underscore) is reserved for implementation, so __cplusplus is ok.

Also, it is wrong to assume that all predefined macros in C++ are upper case. For example, __unix__ is lower-case, as well as bunch of other standard macros listed here: https://en.cppreference.com/w/cpp/preprocessor/replace

SergeyA
  • 61,605
  • 5
  • 78
  • 137
  • `__unix__ ` is non-standard, so I don't think it counts. – HolyBlackCat Feb 12 '19 at 21:57
  • `__unix__` is a standard macro? Where does it say that? Also, there is nothing wrong with curiosity. –  Feb 12 '19 at 21:58
  • @HolyBlackCat I never claimed it to be standard, neither OP asked about standard macros only. They only asked for predefined. – SergeyA Feb 12 '19 at 21:58
  • @NeilButterworth where do I claim it to be standard, or where OP asks about standard macros only? – SergeyA Feb 12 '19 at 21:59
  • Well, of course if we are talking about names of macros you have made up, oops sorry "predefined", I guess anything goes –  Feb 12 '19 at 21:59
  • Thanks for the quick response, I guess I was wrong to assume that all the predefined macros were upper case, however I just wanted to know if there was a particular reason that `__cplusplus` is not `__cplusplus__` for example? –  Feb 12 '19 at 22:00
  • @NeilButterworth, no, this is the macro defined by gcc compiler when compiled on Unix, so it is certainly not made up. It is predefined macro. – SergeyA Feb 12 '19 at 22:01
  • +1 One might quibble but this answer is substantially accurate. See [N4660](http://www.open-std.org/JTC1/SC22/WG21/prot/14882fdis/n4660.pdf), sects. 5.10(3) and 19.8(4). Downvoters might reconsider. – thb Feb 12 '19 at 22:23
  • @thb Link doesn't work - pops up a dialog - nobody sensible will go there. And if you have an answer, post an answer. –  Feb 12 '19 at 22:25
  • 1
    @thb haters going to hate. I am also fully familiar with chain reaction of SO downvotes - 2-3 downvotes and every visitor to the question will feel obliged to downvote as well. I stand beyond my answer, it is factually correct, and I see nothing wrong with it. – SergeyA Feb 12 '19 at 22:25
  • 4
    It doesn't answer my question. There is no conclusive evidence to support what you have said. Also starting your answer with a "This should be of no concern to you" is not exactly the best way to answer someone's question. The only reason I have asked this question is because it IS a concern to me. –  Feb 12 '19 at 22:27
  • 1
    @SergeyA s/beyond/behind/ and your "answer" doesn't answer the question - it's really an uninformed speculation. That's why it is being downvoted. Nothing to do with "haters". –  Feb 12 '19 at 22:27
  • @NeilButterworth Interesting. Instead, [N4659](http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2017/n4659.pdf) still appears to be publicly available, sects. 5.10(3) and 19.8(4). That is a draft of the same document, so you can refer to the draft, instead, if you wish. – thb Feb 12 '19 at 22:41