海湾合作委员会中 -faligned-new 的值
Value of -faligned-new in GCC
我遇到了与此类似的问题 GCC 过度对齐的新支持 (alignas( 所以我添加了-faligned-new
编译器标志。
这修复了编译器警告。但是,当编译器使用--verbose
标志运行时,我得到此输出 https://pastebin.com/X2QZAtSb,其中最重要的行是
COLLECT_GCC_OPTIONS='-o' 'main' '-faligned-new=1' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
海湾合作委员会手册(https://gcc.gnu.org/onlinedocs/gcc-9.3.0/gcc/C_002b_002b-Dialect-Options.html#C_002b_002b-Dialect-Options(指出:
-对齐-新
Enable support for C++17 new of types that require more
alignment than void* ::operator new(std::size_t) provides.
A numeric argument such as -faligned-new=32 can be used to specify how much alignment
(in bytes) is provided by that function, but few users will need to override
the default of alignof(std::max_align_t).
-faligned-new=1
是什么意思?如果我理解正确,它应该等于 8 或 16 或其他什么(默认值为alignof(std::max_align_t)
https://en.cppreference.com/w/cpp/types/max_align_t(,而不是 1。
要重现编译简单的main.cpp:
#include <iostream>
int main() {
std::cout << "hello worldn";
return 0;
}
使用g++ main.cpp -o main -faligned-new --verbose
我正在 Debian 系统上编译 GCC 9.3.0 上的程序,sizeof(max_align_t)
在我的系统上是 32
-faligned-new=1 是什么意思?
显然,这意味着-faligned-new
的使用没有明确的阈值。
根据文档,在这种情况下,阈值默认为std::max_align_t
对齐。
相关文章:
- 数组索引的值没有增加
- 'short int'持有的值溢出,但"自动"不会溢出?
- 是默认情况下分配给char数组常量的值
- 这个指针和内存代码打印是什么?我不知道是打印垃圾还是如何打印我需要的值
- 为什么我无法更改"set<set>"循环中的值<int>
- 有效地使用std::unordered_map来插入或增加键的值
- <streamsize>C++ 中 numeric_limits::max() 的值
- 重载运算符new[]的行为取决于析构函数
- 为什么不能修改对象中的值?另外,我如何改进此链表?
- 使用 new 和 值进行数组初始化,但没有显式数量的元素
- 海湾合作委员会中 -faligned-new 的值
- 我可以从取消引用"new"的返回值初始化引用吗
- 放置 new 的返回值与其操作数的强制转换值之间是否存在(语义)差异
- 检索在函数内部使用运算符new分配的类指针对象成员的值时出现的问题
- 如何在 new[] 的值初始化中使用变量
- 如果 Foo 的构造函数抛出,'Foo *p = new Foo()' 中 p 的值是多少?
- c++的new操作符保证返回的指针不会改变它的值吗?
- 重载new返回的值与this不匹配
- 放置new +析构函数和简单的值初始化语义
- 有没有办法区分new和new[]的返回值?