vsoftco vsoftco - 1 year ago 213
C++ Question

std::align not supported by g++4.9

While learning about alignment issues etc, I realized that my implementation of g++4.9 (macports OS X) does not have support for

. If I try to compile (with
) this example code from http://www.cplusplus.com/reference/memory/align/

// align example
#include <iostream>
#include <memory>

int main() {
char buffer[] = "------------------------";
void * pt = buffer;
std::size_t space = sizeof(buffer) - 1;
while ( std::align(alignof(int), sizeof(char), pt, space) ) {
char* temp = static_cast<char*>(pt);
*temp = '*'; ++temp; space -= sizeof(char);
pt = temp;
std::cout << buffer << '\n';
return 0;

the compiler spits out the error

error: 'align' is not a member of 'std'

This seems strange as g++ seems to have implemented alignment support since g++4.8, https://gcc.gnu.org/projects/cxx0x.html (N2341)

The code compiles under clang++ without any problems.

Is this a well known issue of g++ that I am not aware of? The online compilers that I tested (ideone and coliru) reject the code also.

Answer Source

Yes, this is a known missing feature for gcc :

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download