问题描述
在学习对齐问题等时,我意识到我的g ++ 4.9(macports OS X)的实现不支持 std :: align
。如果我尝试编译( -std = c ++ 11
)这个示例代码从
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;
}
编译器输出错误
error: 'align' is not a member of 'std'
b $ b
这似乎很奇怪,因为g ++似乎已经实现了对齐支持,因为g ++ 4.8,(N2341)
代码在clang ++下编译时没有任何问题。
The code compiles under clang++ without any problems.
这是g ++的一个众所周知的问题,我不知道吗?我测试的在线编译器(ideone和coliru)也拒绝该代码。
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 :
- :
std :: align
缺失
- Bug 53814 :
std::align
missing
这篇关于std :: align不支持g ++ 4.9的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!