C++ Blog

Static Assert in C++0x

Posted in c++0x by Umesh Sirsiwal on January 5, 2009

This is post in the C++ Reference series on this site.

All the C++ programmers have used static asserts some have used Loki version, others have used Boost version or created their own. However, in all cases the error messages generated by Static Assert are incomplete. A language level support is needed to correctly support Static Assert.

The C++0x adds Static Assert to solve this specific issue. The synatx for static assert is something like:

static_assert(sizeof(int) == 4, "Size of int is not 4 bytes.") ;

On any machine where the sizeof(int) is not 4, the compilers should correctly generate error message “Size of int is not 4 bytes”. Sweet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: