在学习有关对齐的问题等等,我意识到,我的实现G ++ 4.9(MacPorts的OS X)不具有的std ::对齐
支持。如果我尝试编译(用 -std = C ++ 11
)的http://www.cplusplus.com/reference/memory/align/
While learning about alignment issues etc, I realized that my implementation of g++4.9 (macports OS X) does not have support for std::align
. If I try to compile (with -std=c++11
) 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'
这似乎很奇怪的G ++似乎因为G ++ 4.8, HTTPS来已经实现对齐支持://gcc.gnu。组织/项目/ cxx0x.html (N2341)
This seems strange as g++ seems to have implemented alignment support since g++4.8, https://gcc.gnu.org/projects/cxx0x.html (N2341)
在code下铛++没有任何问题汇总。
The code compiles under clang++ without any problems.
这是G ++,我不知道的一个众所周知的问题?在线编译器,我测试过(ideone和coliru)拒绝code也。
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.
是的,这是一个已知的缺失功能的GCC:
Yes, this is a known missing feature for gcc :
错误53814 :的std ::对齐
丢失