Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is static_assert compiled into the binary file

I’d like to use static_assert in my C++11 project to do some compile time check.

As my understanding, static_assert won’t be executed at runtime, right?

If so, when I compile my project by executing the command about compilation, such as gcc ..., the compiler will build the static_assert into the binary file or the static_assert will be totally ignored, just like a comment?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Is static_assert compiled into the binary file

No.

As my understanding, static_assert won’t be executed at runtime, right?

Right.

the compiler will build the static_assert into the binary file

No.

the static_assert will be totally ignored, just like a comment?

No, it’s not a comment – the expression is checked, and if the expression is false, then a message is shown. When the expression is not a constant (can’t be computed at compile time) then also a message is shown.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading