7

There are more operators that work when we add __ to them too. what does __ mean?

vonmangle
  • 113
  • 1
  • 8
a-z
  • 1,634
  • 4
  • 16
  • 35
  • 3
    typeof is not a function, it is an operator. –  Oct 01 '11 at 07:44
  • 3
    Possible duplicate of [What does double underscore ( __const) mean in C?](http://stackoverflow.com/questions/1449181/what-does-double-underscore-const-mean-in-c). – Frédéric Hamidi Oct 01 '11 at 08:08
  • @WTP: That depends on how it is defined. It's just an identifier, it has no special meaning in C++ so it could be "#defined" to an operator or declared as a function. – CB Bailey Oct 01 '11 at 11:52

1 Answers1

4

An identifier with double underscores is reserved for the implementation. typeof is a compiler specific extension to the language, so naming it __typeof ensures no user code has an identifier with the same name

Dennis Zickefoose
  • 10,791
  • 3
  • 29
  • 38
  • so why both typeof and __typeof are defined? – a-z Oct 02 '11 at 05:20
  • 1
    @user913461: I believe gcc has an option to disable the former, but not the later. So if you have a file that uses `typeof` as an identifier, you can still get it to compile by disabling the `typeof` operator, but leaving the `__typeof` operator alone. – Dennis Zickefoose Oct 02 '11 at 06:23
  • 1
    The double-underscore version is needed for compilers running in extremely strict standard compliance modes (like `gcc` with the `-ansi` or `-std` option). When running with all of the normal gcc extensions enabled, the underscore-free version is available. You will often see this on identifiers that are either compiler extensions or not available in every version of the language standard (`inline` is another example). – bta Nov 01 '11 at 22:23