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:
Read more about this topic: C++11, Core Language Functionality Improvements
Famous quotes containing the words control, query and/or object:
“Why wont they let a year die without bringing in a new one on the instant, cant they use birth control on time? I want an interregnum. The stupid years patter on with unrelenting feet, never stoppingrising to little monotonous peaks in our imaginations at festivals like New Years and Easter and ChristmasBut, goodness, why need they do it?”
—John Dos Passos (18961970)
“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 questionthe 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 (18391894)
“The division between the useful arts and the fine arts must not be understood in too absolute a manner. In the humblest work of the craftsmen, if art is there, there is a concern for beauty, through a kind of indirect repercussion that the requirements of the creativity of the spirit exercise upon the production of an object to serve human needs.”
—Jacques Maritain (18821973)