C++11 - Core Language Functionality Improvements - Control and Query Object Alignment

Control and Query Object Alignment

C++11 allows variable alignment to be queried and controlled with alignof and alignas.

The alignof operator takes a type and returns the power of 2 byte boundary on which the type instances must be allocated (as a std::size_t). When given a reference type alignof returns the referenced type's alignment; for arrays it returns the element type's alignment.

The alignas specifier controls the memory alignment for a variable. The specifier takes a constant or a type; when supplied a type alignas(T) is short hand for alignas(alignof(T)). For example, to specify that a char array should be properly aligned to hold a float:

alignas(float) unsigned char c

Read more about this topic:  C++11, Core Language Functionality Improvements

Famous quotes containing the words control, query and/or object:

    The poets were not alone in sanctioning myths, for long before the poets the states and the lawmakers had sanctioned them as a useful expedient.... They needed to control the people by superstitious fears, and these cannot be aroused without myths and marvels.
    Strabo (c. 58 B.C.–c. 24 A.D., Greek geographer. Geographia, bk. 1, sct. 2, subsct. 8.

    Such condition of suspended judgment indeed, in its more genial development and under felicitous culture, is but the expectation, the receptivity, of the faithful scholar, determined not to foreclose what is still a question—the “philosophic temper,” in short, for which a survival of query will be still the salt of truth, even in the most absolutely ascertained knowledge.
    Walter Pater (1839–1894)

    It has never been my object to record my dreams, just the determination to realize them.
    Man Ray (1890–1976)