_Static_assert - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# _Static_assert

From cppreference.com
< c‎ | keyword

_Static_assert evaluates a constant expression at compile time. If the expression is equal to 0, the compiler will produce an error message containing the string literal given as the second parameter.

| This section is incomplete Reason: write a page on static_assert-declaration, move content from here

### [edit] Parameters

condition | - | constant expression
str | - | string literal

### [edit] Return Value

(none)

### [edit] Example

Run this code

    #define BUFFER_SIZE 2048

    int main (int argc, char **argv)
    {
    	// Test if math works.
    	_Static_assert(2 + 2 == 4, "Whoa dude!");

            // This will produce an error at compile time.
            _Static_assert(BUFFER_SIZE <= 1024, "BUFFER_SIZE is too big");

    	return 0;
    }

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=c/keyword/_Static_assert&oldid=70419"
Category:

- Todo with reason