2017-08-09 110 views
3

g ++支持sclar_storage_orderg ++是否支持scalar_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 
+1

「警告」什麼?請告訴我們警告。 –

+1

有一個很酷的網站叫做www.google.com。我所要做的只是輸入「scalar_storage_order gcc」。並立即返回鏈接到這個問題的答案:https://gcc.gnu.org/onlinedocs/gcc/Structure-Layout-Pragmas.html –

+0

@Someprogrammerdude更新了我的問題 – makerj

回答

3

一個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. 

合併後的補丁註冊表rs爲C和C++的#pragma scalar_storage_order處理程序,但C++前端未更改爲處理受編譯指示控制的內部global_sso標誌,因此目前在g ++中不支持此功能。