The <QtCompilerDetection> header file includes various compiler-specific macros. 更多...
头: | #include <QtCompilerDetection> |
The <QtCompilerDetection> header file provides a range of macros (Q_CC_*) that are defined if the application is compiled using the specified compiler. For example, the Q_CC_SUN macro is defined if the application is compiled using Forte Developer, or Sun Studio C++.
The purpose of these macros is to enable programmers to add compiler-specific code to their application.
Defined if the application is compiled using Borland/Turbo C++.
Defined if the application is compiled using Reliant C++.
Defined if the application is compiled using Clang.
Defined if the application is compiled using Comeau C++.
Defined if the application is compiled using DEC C++.
Defined if the application is compiled using Edison Design Group C++.
Defined if the application is compiled using Green Hills Optimizing C++ Compilers.
Defined if the application is compiled using GNU Compiler Collection (GCC).
Defined if the application is compiled using MetaWare High C/C++.
Defined if the application is compiled using HP aC++.
Defined if the application is compiled using KAI C++.
Defined if the application is compiled using MIPSpro C++.
Defined if the application is compiled using Microsoft Visual C/C++, Intel C++ for Windows.
Defined if the application is compiled using CenterLine C++.
Defined if the application is compiled using Portland Group C++.
Defined if the application is compiled using Forte Developer, or Sun Studio C++.
Defined if the application is compiled using Digital Mars C/C++ (used to be Symantec C++).
Defined if the application is compiled using SCO OUDK and UDK.
Defined if the application is compiled using Watcom C++.
[since 6.4]
Q_CONSTINIT
Enforces constant initialization when supported by the compiler.
If the compiler supports the C++20
constinit
keyword, Clang's
[[clang::require_constant_initialization]]
or GCC's
__constinit
, then this macro expands to the first one of these that is available, otherwise it expands to nothing.
Variables marked as
constinit
cause a compile-error if their initialization would have to be performed at runtime.
注意: Constant-initialized variables may still have load-time impact if they have non-trivial destruction.
For constants, you can use
constexpr
since C++11, but
constexpr
makes variables
const
, too, whereas
constinit
ensures constant initialization, but doesn't make the variable
const
:
Keyword | 添加 | immutable | constant-initialized |
---|---|---|---|
const
|
C++98 | yes | not required |
constexpr
|
C++11 | yes | required |
constinit
|
C++20 | no | required |
This macro was introduced in Qt 6.4.
This macro marks a symbol for shared library export (see 创建共享库 ).
另请参阅 Q_DECL_IMPORT .
This macro declares a symbol to be an import from a shared library (see 创建共享库 ).
另请参阅 Q_DECL_EXPORT .
Can be used in switch statements at the end of case block to tell the compiler and other developers that that the lack of a break statement is intentional.
This is useful since a missing break statement is often a bug, and some compilers can be configured to emit warnings when one is not found.
另请参阅 Q_UNREACHABLE () 和 Q_UNREACHABLE_RETURN ().
Expands to a string that describe the function the macro resides in. How this string looks more specifically is compiler dependent. With GNU GCC it is typically the function signature, while with other compilers it might be the line and column number.
Q_FUNC_INFO can be conveniently used with qDebug ()。例如,此函数:
template<typename TInputType> const TInputType &myMin(const TInputType &value1, const TInputType &value2) { qDebug() << Q_FUNC_INFO << "was called with value1:" << value1 << "value2:" << value2; if(value1 < value2) return value1; else return value2; }
when instantiated with the integer type, will with the GCC compiler produce:
const TInputType& myMin(const TInputType&, const TInputType&) [with TInputType = int] was called with value1: 3 value2: 4
If this macro is used outside a function, the behavior is undefined.
Hints to the compiler that the enclosed condition,
expr
, is likely to evaluate to
true
.
Use of this macro can help the compiler to optimize the code.
范例:
// the condition inside the "if" will be successful most of the times for (int i = 1; i <= 365; i++) { if (Q_LIKELY(isWorkingDay(i))) { ... } ... }
另请参阅 Q_UNLIKELY () 和 Q_ASSUME ().
Hints to the compiler that the enclosed condition,
expr
, is likely to evaluate to
false
.
Use of this macro can help the compiler to optimize the code.
范例:
bool readConfiguration(const QFile &file) { // We expect to be asked to read an existing file if (Q_UNLIKELY(!file.exists())) { qWarning() << "File not found"; return false; } ... return true; }
另请参阅 Q_LIKELY ().