IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

<QtCompilerDetection> - Compiler-specific Macro Definitions

The <QtCompilerDetection> header file includes various compiler-specific macros.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

<QtCompilerDetection> - Compiler-specific Macro Definitions

  • Header: QtCompilerDetection

  • Group: <QtCompilerDetection> is part of funclists

I. Detailed Description

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.

II. Macro Documentation

 

II-1. Q_CC_BOR

Defined if the application is compiled using Borland/Turbo C++.

II-2. Q_CC_CDS

Defined if the application is compiled using Reliant C++.

II-3. Q_CC_CLANG

Defined if the application is compiled using Clang.

II-4. Q_CC_COMEAU

Defined if the application is compiled using Comeau C++.

II-5. Q_CC_DEC

Defined if the application is compiled using DEC C++.

II-6. Q_CC_EDG

Defined if the application is compiled using Edison Design Group C++.

II-7. Q_CC_GHS

Defined if the application is compiled using Green Hills Optimizing C++ Compilers.

II-8. Q_CC_GNU

Defined if the application is compiled using GNU Compiler Collection (GCC).

II-9. Q_CC_HIGHC

Defined if the application is compiled using MetaWare High C/C++.

II-10. Q_CC_HPACC

Defined if the application is compiled using HP aC++.

II-11. Q_CC_KAI

Defined if the application is compiled using KAI C++.

II-12. Q_CC_MIPS

Defined if the application is compiled using MIPSpro C++.

II-13. Q_CC_MSVC

Defined if the application is compiled using Microsoft Visual C/C++, Intel C++ for Windows.

II-14. Q_CC_OC

Defined if the application is compiled using CenterLine C++.

II-15. Q_CC_PGI

Defined if the application is compiled using Portland Group C++.

II-16. Q_CC_SUN

Defined if the application is compiled using Forte Developer, or Sun Studio C++.

II-17. Q_CC_SYM

Defined if the application is compiled using Digital Mars C/C++ (used to be Symantec C++).

II-18. Q_CC_USLC

Defined if the application is compiled using SCO OUDK and UDK.

II-19. Q_CC_WAT

Defined if the application is compiled using Watcom C++.

II-20. [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

Added

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.

II-21. Q_DECL_EXPORT

This macro marks a symbol for shared library export (see Creating Shared Libraries).

II-21-1. See Also

See also Q_DECL_IMPORT

II-22. Q_DECL_IMPORT

This macro declares a symbol to be an import from a shared library (see Creating Shared Libraries).

II-22-1. See Also

See also Q_DECL_EXPORT

II-23. void Q_FALLTHROUGH

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.

II-23-1. See Also

II-24. const char*Q_FUNC_INFO

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(). For example, this function:

 
Sélectionnez
template&lt;typename TInputType&gt;
const TInputType &amp;myMin(const TInputType &amp;value1, const TInputType &amp;value2)
{
    qDebug() &lt;&lt; Q_FUNC_INFO &lt;&lt; "was called with value1:" &lt;&lt; value1 &lt;&lt; "value2:" &lt;&lt; value2;

    if(value1 &lt; 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.

II-25. Q_LIKELY(expr)

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.

Example:

 
Sélectionnez
    // the condition inside the "if" will be successful most of the times
    for (int i = 1; i &lt;= 365; i++) {
        if (Q_LIKELY(isWorkingDay(i))) {
            ...
        }
        ...
    }
II-25-1. See Also

See also Q_UNLIKELY(), Q_ASSUME()

II-26. Q_UNLIKELY(expr)

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.

Example:

 
Sélectionnez
bool readConfiguration(const QFile &amp;file)
{
    // We expect to be asked to read an existing file
    if (Q_UNLIKELY(!file.exists())) {
        qWarning() &lt;&lt; "File not found";
        return false;
    }

    ...
    return true;
}
II-26-1. See Also

See also Q_LIKELY()

III. Obsolete Members for <QtCompilerDetection>

The following members of class <QtCompilerDetection> are deprecated. We strongly advise against using them in new code.

III-1. Obsolete Macro Documentation

 
III-1-1. Q_CC_INTEL

This macro is deprecated. We strongly advise against using it in new code.

This macro used to be defined if the application was compiled with the old Intel C++ compiler for Linux, macOS or Windows. The new oneAPI C++ compiler is just a build of Clang and therefore does not define this macro.

III-1-1-1. See Also

See also Q_CC_CLANG

III-1-2. Q_DECL_CONSTEXPR

This macro is deprecated since 6.4. We strongly advise against using it in new code.

Use the constexpr keyword instead.

This macro can be used to declare variable that should be constructed at compile-time, or an inline function that can be computed at compile-time.

III-1-2-1. See Also
III-1-3. Q_DECL_FINAL

This macro is deprecated. We strongly advise against using it in new code.

This macro can be used to declare an overriding virtual or a class as "final", with Java semantics. Further-derived classes can then no longer override this virtual function, or inherit from this class, respectively.

It expands to "final".

The macro goes at the end of the function, usually after the const, if any:

 
Sélectionnez
    // more-derived classes no longer permitted to override this:
    virtual void MyWidget::paintEvent(QPaintEvent*) final;

For classes, it goes in front of the : in the class definition, if any:

 
Sélectionnez
    class QRect final { // cannot be derived from
        // ...
    };
III-1-3-1. See Also

See also Q_DECL_OVERRIDE

III-1-4. Q_DECL_NOEXCEPT

This macro is deprecated since 6.4. We strongly advise against using it in new code.

Use the noexcept keyword instead.

This macro marks a function as never throwing. If the function does nevertheless throw, the behavior is defined: std::terminate() is called.

III-1-4-1. See Also
III-1-5. Q_DECL_NOEXCEPT_EXPR(x)

This macro is deprecated since 6.4. We strongly advise against using it in new code.

Use the noexcept keyword instead.

This macro marks a function as non-throwing if x is true. If the function does nevertheless throw, the behavior is defined: std::terminate() is called.

III-1-5-1. See Also
III-1-6. Q_DECL_NOTHROW

This macro is deprecated since 6.4. We strongly advise against using it in new code.

Use the noexcept keyword instead.

This macro marks a function as never throwing, under no circumstances. If the function does nevertheless throw, the behavior is undefined.

III-1-6-1. See Also
III-1-7. Q_DECL_OVERRIDE

This macro is deprecated. We strongly advise against using it in new code.

This macro can be used to declare an overriding virtual function. Use of this markup will allow the compiler to generate an error if the overriding virtual function does not in fact override anything.

It expands to "override".

The macro goes at the end of the function, usually after the const, if any:

 
Sélectionnez
    // generate error if this doesn't actually override anything:
    virtual void MyWidget::paintEvent(QPaintEvent*) override;
III-1-7-1. See Also

See also Q_DECL_FINAL

III-1-8. Q_DECL_RELAXED_CONSTEXPR

This macro is deprecated since 6.4. We strongly advise against using it in new code.

Use the constexpr keyword instead.

This macro can be used to declare an inline function that can be computed at compile-time according to the relaxed rules from C++14.

III-1-8-1. See Also

See also Q_DECL_CONSTEXPR

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+