Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does g++ support scalar_storage_order?

Tags:

c++

g++

Does g++ support sclar_storage_order?

I've tested it in g++6 and g++7, but it only warns and does not handle it properly.

Source Code:

#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;
}

Output:

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
like image 612
makerj Avatar asked Oct 23 '25 18:10

makerj


1 Answers

A patch for the C++ front end was posted, but it was reverted on the branch before the merge:

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

The merged patch registers the #pragma scalar_storage_order handler for both C and C++, but the C++ front end was not changed to process the internal global_sso flag controlled by the pragma, so there is currently no support whatsoever for this feature in g++.

like image 189
Florian Weimer Avatar answered Oct 26 '25 06:10

Florian Weimer