gpt4 book ai didi

c++ - g++ 是否支持 scalar_storage_order?

转载 作者:太空狗 更新时间:2023-10-29 21:13:04 25 4
gpt4 key购买 nike

g++ 是否支持 sclar_storage_order

我在g++6和g++7中测试过,但是只是警告,并没有正确处理。

源代码:

#ifdef __cplusplus
#include <cstdio>
#include <cstdint>
#else
#include <stdio.h>
#include <stdint.h>
#endif

typedef struct {
uint32_t a;
uint16_t b;
} __attribute__((scalar_storage_order("big-endian"))) SS;


int main(int argc, char *argv[]) {
uint8_t raw[] = { 0xaa, 0xbb, 0xcc, 0xdd, 0x11, 0x22 };
SS* instance = (SS*)raw;
printf("%x, %x\n", instance->a, instance->b);
return 0;
}

输出:

gcc-6 source.c && ./a.out
aabbccdd, 1122

g++-6 source.cpp && ./a.out
source.cpp:16:53: warning: ‘scalar_storage_order’ attribute ignored [-Wattributes]
} __attribute__((scalar_storage_order("big-endian"))) SS;
^
ddccbbaa, 2211

最佳答案

A patch for the C++ front end was posted , 但它在合并前在分支上恢复了:

------------------------------------------------------------------------
r229934 | ebotcazou | 2015-11-07 19:10:36 +0100 (Sat, 07 Nov 2015) | 8 lines

c-family/
* c-common.c (handle_scalar_storage_order_attribute): Accept attribute
in place in C but not in C++.
testsuite/
* c-c++-common/sso-[1-7].c: Move to...
* gcc.dg/sso-[2-8].c: ...here.
* g++.dg/sso-[2-8].C: ... and here.

合并后的补丁为 C 和 C++ 注册了 #pragma scalar_storage_order 处理程序,但 C++ 前端未更改为处理由 pragma 控制的内部 global_sso 标志,因此目前在 g++ 中不支持此功能。

关于c++ - g++ 是否支持 scalar_storage_order?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45589653/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com