C++what is the type of the __LINE__ macro

C++03 §16.8p1:

__LINE__ The line number of the current source line (a decimal constant).

This will either be int, or if INT_MAX (which is allowed to be as little as 32,767) is not big enough (… I won't ask …), then it will be long int. If it would be bigger than LONG_MAX, then you have undefined behavior, which, for once, is not a problem worth worrying about in a file of at least 2,147,483,647 lines (the minimum allowed value for LONG_MAX).

The same section also lists other macros you may be interested in.


The C++ standard simply has this to say:

__LINE__: The presumed line number (within the current source file) of the current source line (an integer constant).

It does not actually state the type so it's most likely going to be the same type as an unadorned integer would be in your source code which would be an int. The fact that the upper end of the allowed range is 2G - 1 supports that (even though the lower range is 1).

The fact that #line only allows digits (no trailing U to make it unsigned) can also be read to support this.

But, that's only support. I couldn't find a definitive statement within either the C++ or C standards. It just makes sense*a that it will be translated into something like 42 when it goes through the preprocessing phase and that's what the compiler will see, treating it exactly like 42 (an int).


*a: This wouldn't be the first time my common sense was wrong, though :-)