Search results
Dec 18, 2022 · __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 .
How can I replace my c++ exception macro with an inline function with __LINE__ and __FILE__ support?
- Overview
- Standard predefined identifier
- Standard predefined macros
- Microsoft-specific predefined macros
The Microsoft C/C++ compiler (MSVC) predefines certain preprocessor macros depending on the language (C or C++), the compilation target, and the chosen compiler options.
MSVC supports the predefined preprocessor macros required by the ANSI/ISO C99, C11, and C17 standards, and the ISO C++14, C++17, and C++20 standards. The implementation also supports several more Microsoft-specific preprocessor macros.
The compiler supports this predefined identifier specified by ISO C99 and ISO C++11.
•__func__ The unqualified and unadorned name of the enclosing function as a function-local static const array of char.
The compiler supports these predefined macros specified by the ISO C99, C11, C17, and ISO C++17 standards.
•__cplusplus Defined as an integer literal value when the translation unit is compiled as C++. Otherwise, undefined.
•__DATE__ The compilation date of the current source file. The date is a constant length string literal of the form Mmm dd yyyy. The month name Mmm is the same as the abbreviated month name generated by the C Runtime Library (CRT) asctime function. The first character of date dd is a space if the value is less than 10. This macro is always defined.
•__FILE__ The name of the current source file. __FILE__ expands to a character string literal. To ensure that the full path to the file is displayed, use /FC (Full Path of Source Code File in Diagnostics). This macro is always defined.
•__LINE__ Defined as the integer line number in the current source file. The value of this macro can be changed by using a #line directive. The integral type of the value of __LINE__ can vary depending on context. This macro is always defined.
•__STDC__ Defined as 1 when compiled as C and if the /Za compiler option is specified. Starting in Visual Studio 2022 version 17.2, it's defined as 1 when compiled as C and if the /std:c11 or /std:c17 compiler option is specified. Otherwise, undefined.
MSVC supports other predefined macros:
•__ATOM__ Defined as 1 when the /favor:ATOM compiler option is set and the compiler target is x86 or x64. Otherwise, undefined.
•__AVX__ Defined as 1 when the /arch:AVX, /arch:AVX2, or /arch:AVX512 compiler options are set and the compiler target is x86 or x64. Otherwise, undefined.
•__AVX2__ Defined as 1 when the /arch:AVX2 or /arch:AVX512 compiler option is set and the compiler target is x86 or x64. Otherwise, undefined.
•__AVX512BW__ Defined as 1 when the /arch:AVX512 compiler option is set and the compiler target is x86 or x64. Otherwise, undefined.
•__AVX512CD__ Defined as 1 when the /arch:AVX512 compiler option is set and the compiler target is x86 or x64. Otherwise, undefined.
For example, "/usr/local/include/myheader.h" is a possible expansion of this macro. __LINE__. This macro expands to the current input line number, in the form of a decimal integer constant. While we call it a predefined macro, it’s a pretty strange macro, since its “definition” changes with each new line of source code.
__LINE__ is a preprocessor macro that expands to current line number in the source file, as an integer. __LINE__ is useful when generating log statements, error messages intended for programmers, when throwing exceptions , or when writing debugging code.
Nov 11, 2023 · The following are some commonly used predefined macros in C++: __LINE__: This macro expands to the current line number in the source code. __FILE__: This macro expands to the name of the current source file. __DATE__: This macro expands to a string that represents the date of compilation.
People also ask
What is __line__ macro?
Does __line__ need a macro?
Can a macro be used instead of a line in C++?
What is a multiline macro?
What are predefined macros in C++?
Is __file__ a macro?
May 27, 2022 · Explanation. 1) Changes the current preprocessor line number to lineno. Occurrences of the macro __LINE__ beyond this point will expand to lineno plus the number of actual source code lines encountered since. 2) Also changes the current preprocessor file name to filename.