Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
C++CodeIDERAD Studio

Quickly Learn How To Use C++ Static Assertions For Windows Development With C++Builder

Static assertions is a feature supported by both BCC32 and the Clang-enhanced C++ compilers. The static_assert keyword is used to test assertions at compile time. This is one of the C++11 features added to BCC32. This keyword operates differently than the macro assert, which raises assertions at run time. The keyword static_assert also differs from the preprocessor directive #error, which operates during preprocessing and simply emits a message.

A static assertion’s declaration is:

The constant-expression must be one that can be statically evaluated as a boolean. If constant-expression is true, the statement does nothing. If false, the compiler generates an error with the text error-message. Because the assertion is tested at compile time, static_assert can do error checking in templates. For instance:

Erroneous static_assert

The constant_expression passed in static_assertion needs to be a valid expression. For example, consider the following code:

On compiling above code the C++ Builder compiler flash following error.

static_assert expression is not an integral constant expression
<File name and line number>: division by zero

Find out more about C++ static assertions for Windows development in the Embarcadero DocWiki.

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

Related posts

Measure Heart Rate Using Delphi And C++ Builder With The Power Of ThingConnect IoT Device Component Pack


Create Enterprise-Grade WebSockets Based Apps With Powerful Components For Delphi


Incredibly Powerful Enhanced Terminal And Network Toolkit For Windows Is Built In Delphi

C++CodeRAD Studio

Learn How To Use C++ Explicit Virtual Overrides In Windows Development

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.