Top "Static-assert" questions

An assertion statement that is verified at the compilation time.

Static assert in C

What's the best way to achieve compile time static asserts in C (not C++), with particular emphasis on GCC?

c gcc assert compile-time static-assert
What does static_assert do, and what would you use it for?

Could you give an example where static_assert(...) ('C++11') would solve the problem in hand elegantly? I am familiar …

c++ debugging c++11 assert static-assert
Use static_assert to check types passed to macro

I unfortunately have several macros left over from the original version of my library that employed some pretty crazy C. …

c++ c visual-studio-2010 g++ static-assert
How do I restrict a template class to certain built-in types?

This issue has been discussed a few times but all the solutions I have found either didn't work or were …

c++ templates visual-studio-2012 c++11 static-assert
How to check the size of a structure at compile time?

I want to add code that during compilation checks the size of a structure to make sure that it is …

c++ data-structures static-assert
Enforce template type through static_assert

I'm trying to understand the usefulness of static_assert, and I want to know if it can help me in …

c++ templates template-specialization static-assert
Does GCC have a built-in compile time assert?

Our existing compile-time assert implementation is based on negative array index, and it provides poor diagnostic output on GCC. C++0…

c++ gcc static-assert
Ways to ASSERT expressions at build time in C

I'm tidying up some older code that uses 'magic numbers' all over the place to set hardware registers, and I …

c refactoring assert static-assert
static_assert fails compilation even though template function is called nowhere

I use g++ 4.6.3, (currently default package for ubuntu 12.04) with the flag c++0x, and I stumble across this: template <…

c++ templates c++11 g++ static-assert
C++11 - static_assert within constexpr function?

How would one properly do a static_assert within a constexpr function? For example: constexpr int do_something(int x) { …

c++ c++11 static-assert constexpr