Compound literals doesn't work

When I use compound literals like

#define VECTOR_ROOT_E131_DATA (uint8_t[]){0x00, 0x00, 0x00, 0x04}

I get following error message:

lib/sACN/src/sACNDefs.h:76:42: error: taking address of temporary array
   76 | #define VECTOR_ROOT_E131_DATA (uint8_t[]){0x00, 0x00, 0x00, 0x04}

The compound literals works fine when using code runner on macOS with clang.

Here is an example for Arduino IDE using Raspberry Pi Pico

#define ACN_IDENTIFIER "ASC-E1.17\0\0\0"
uint8_t identifier[12] = "ASC-E1.17";
uint8_t ident[12] = {0};

//#define VECTOR_ROOT_E131_DATA 0x00000004
#define VECTOR_ROOT_E131_DATA (uint8_t[]){0x00, 0x00, 0x00, 0x04}
uint8_t vector[4] = {0x00, 0x00, 0x00, 0x04};
uint8_t vec[4] = {0};

void setup() {
	Serial.begin(9600);

	int equal1 = memcmp(identifier, ACN_IDENTIFIER, 12);
	printf("ACN compare %d\n", equal1);
	memcpy(ident, ACN_IDENTIFIER, 12);
	Serial.printf("ACN %s\n", ident);
	
	int equal2 = memcmp(vector, VECTOR_ROOT_E131_DATA, 4);
	printf("Vector compare %d\n", equal2);
	memcpy(vec, VECTOR_ROOT_E131_DATA, 4);
	Serial.printf("Vector 0x%x 0x%x 0x%x 0x%x\n", vec[0], vec[1], vec[2], vec[3]);

}

void loop() {
  // put your main code here, to run repeatedly:

}

and the error message:


FQBN: rp2040:rp2040:rpipico
Using board 'rpipico' from platform in folder: /Users/sstaub/Library/Arduino15/packages/rp2040/hardware/rp2040/3.9.5
Using core 'rp2040' from platform in folder: /Users/sstaub/Library/Arduino15/packages/rp2040/hardware/rp2040/3.9.5

Detecting libraries used...
/Users/sstaub/Library/Arduino15/packages/rp2040/tools/pqt-gcc/2.2.0-d04e724/bin/arm-none-eabi-g++ -I /private/var/folders/vd/yv1mb7lx6gn7ymffgtjk6hx80000gn/T/arduino/sketches/0CD56E42A202B01F908E5D10B761265C/core -c -Werror=return-type -Wno-psabi -DCFG_TUSB_MCU=OPT_MCU_RP2040 -DUSBD_PID=0x000a -DUSBD_VID=0x2e8a -DUSBD_MAX_POWER_MA=250 -DUSB_MANUFACTURER="Raspberry Pi" -DUSB_PRODUCT="Pico" -DPICO_CYW43_ARCH_THREADSAFE_BACKGROUND=1 -DCYW43_LWIP=1 -DLWIP_IPV6=0 -DLWIP_IPV4=1 -DLWIP_IGMP=1 -DLWIP_CHECKSUM_CTRL_PER_NETIF=1 -DARDUINO_VARIANT="rpipico" -DTARGET_RP2040 -DPICO_FLASH_SIZE_BYTES=2097152 -march=armv6-m -mcpu=cortex-m0plus -mthumb -ffunction-sections -fdata-sections -fno-exceptions -DARM_MATH_CM0_FAMILY -DARM_MATH_CM0_PLUS -iprefix/Users/sstaub/Library/Arduino15/packages/rp2040/hardware/rp2040/3.9.5/ @/Users/sstaub/Library/Arduino15/packages/rp2040/hardware/rp2040/3.9.5/lib/platform_inc.txt -I/Users/sstaub/Library/Arduino15/packages/rp2040/hardware/rp2040/3.9.5/include -fno-rtti -std=gnu++17 -g -pipe -w -x c++ -E -CC -DF_CPU=133000000L -DARDUINO=10607 -DARDUINO_RASPBERRY_PI_PICO -DBOARD_NAME="RASPBERRY_PI_PICO" -DARDUINO_ARCH_RP2040 -Os -DWIFICC=CYW43_COUNTRY_WORLDWIDE -I/Users/sstaub/Library/Arduino15/packages/rp2040/hardware/rp2040/3.9.5/cores/rp2040 -I/Users/sstaub/Library/Arduino15/packages/rp2040/hardware/rp2040/3.9.5/variants/rpipico /private/var/folders/vd/yv1mb7lx6gn7ymffgtjk6hx80000gn/T/arduino/sketches/0CD56E42A202B01F908E5D10B761265C/sketch/Compound_Literal.ino.cpp -o /dev/null
Generating function prototypes...
/Users/sstaub/Library/Arduino15/packages/rp2040/tools/pqt-gcc/2.2.0-d04e724/bin/arm-none-eabi-g++ -I /private/var/folders/vd/yv1mb7lx6gn7ymffgtjk6hx80000gn/T/arduino/sketches/0CD56E42A202B01F908E5D10B761265C/core -c -Werror=return-type -Wno-psabi -DCFG_TUSB_MCU=OPT_MCU_RP2040 -DUSBD_PID=0x000a -DUSBD_VID=0x2e8a -DUSBD_MAX_POWER_MA=250 -DUSB_MANUFACTURER="Raspberry Pi" -DUSB_PRODUCT="Pico" -DPICO_CYW43_ARCH_THREADSAFE_BACKGROUND=1 -DCYW43_LWIP=1 -DLWIP_IPV6=0 -DLWIP_IPV4=1 -DLWIP_IGMP=1 -DLWIP_CHECKSUM_CTRL_PER_NETIF=1 -DARDUINO_VARIANT="rpipico" -DTARGET_RP2040 -DPICO_FLASH_SIZE_BYTES=2097152 -march=armv6-m -mcpu=cortex-m0plus -mthumb -ffunction-sections -fdata-sections -fno-exceptions -DARM_MATH_CM0_FAMILY -DARM_MATH_CM0_PLUS -iprefix/Users/sstaub/Library/Arduino15/packages/rp2040/hardware/rp2040/3.9.5/ @/Users/sstaub/Library/Arduino15/packages/rp2040/hardware/rp2040/3.9.5/lib/platform_inc.txt -I/Users/sstaub/Library/Arduino15/packages/rp2040/hardware/rp2040/3.9.5/include -fno-rtti -std=gnu++17 -g -pipe -w -x c++ -E -CC -DF_CPU=133000000L -DARDUINO=10607 -DARDUINO_RASPBERRY_PI_PICO -DBOARD_NAME="RASPBERRY_PI_PICO" -DARDUINO_ARCH_RP2040 -Os -DWIFICC=CYW43_COUNTRY_WORLDWIDE -I/Users/sstaub/Library/Arduino15/packages/rp2040/hardware/rp2040/3.9.5/cores/rp2040 -I/Users/sstaub/Library/Arduino15/packages/rp2040/hardware/rp2040/3.9.5/variants/rpipico /private/var/folders/vd/yv1mb7lx6gn7ymffgtjk6hx80000gn/T/arduino/sketches/0CD56E42A202B01F908E5D10B761265C/sketch/Compound_Literal.ino.cpp -o /private/var/folders/vd/yv1mb7lx6gn7ymffgtjk6hx80000gn/T/629566102/sketch_merged.cpp
/Users/sstaub/Library/Arduino15/packages/builtin/tools/ctags/5.8-arduino11/ctags -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives /private/var/folders/vd/yv1mb7lx6gn7ymffgtjk6hx80000gn/T/629566102/sketch_merged.cpp
Compiling sketch...
/Users/sstaub/Library/Arduino15/packages/rp2040/tools/pqt-python3/1.0.1-base-3a57aed/python3 -I /Users/sstaub/Library/Arduino15/packages/rp2040/hardware/rp2040/3.9.5/tools/signing.py --mode header --publickey /Users/sstaub/Documents/Arduino/Compound_Literal/public.key --out /private/var/folders/vd/yv1mb7lx6gn7ymffgtjk6hx80000gn/T/arduino/sketches/0CD56E42A202B01F908E5D10B761265C/core/Updater_Signing.h
/Users/sstaub/Library/Arduino15/packages/rp2040/tools/pqt-gcc/2.2.0-d04e724/bin/arm-none-eabi-g++ -I /private/var/folders/vd/yv1mb7lx6gn7ymffgtjk6hx80000gn/T/arduino/sketches/0CD56E42A202B01F908E5D10B761265C/core -c -Wall -Wextra -Werror=return-type -Wno-ignored-qualifiers -Wno-psabi -DCFG_TUSB_MCU=OPT_MCU_RP2040 -DUSBD_PID=0x000a -DUSBD_VID=0x2e8a -DUSBD_MAX_POWER_MA=250 "-DUSB_MANUFACTURER=\"Raspberry Pi\"" "-DUSB_PRODUCT=\"Pico\"" -DPICO_CYW43_ARCH_THREADSAFE_BACKGROUND=1 -DCYW43_LWIP=1 -DLWIP_IPV6=0 -DLWIP_IPV4=1 -DLWIP_IGMP=1 -DLWIP_CHECKSUM_CTRL_PER_NETIF=1 "-DARDUINO_VARIANT=\"rpipico\"" -DTARGET_RP2040 -DPICO_FLASH_SIZE_BYTES=2097152 -march=armv6-m -mcpu=cortex-m0plus -mthumb -ffunction-sections -fdata-sections -fno-exceptions -DARM_MATH_CM0_FAMILY -DARM_MATH_CM0_PLUS -MMD -iprefix/Users/sstaub/Library/Arduino15/packages/rp2040/hardware/rp2040/3.9.5/ @/Users/sstaub/Library/Arduino15/packages/rp2040/hardware/rp2040/3.9.5/lib/platform_inc.txt -I/Users/sstaub/Library/Arduino15/packages/rp2040/hardware/rp2040/3.9.5/include -fno-rtti -std=gnu++17 -g -pipe -DF_CPU=133000000L -DARDUINO=10607 -DARDUINO_RASPBERRY_PI_PICO "-DBOARD_NAME=\"RASPBERRY_PI_PICO\"" -DARDUINO_ARCH_RP2040 -Os -DWIFICC=CYW43_COUNTRY_WORLDWIDE -I/Users/sstaub/Library/Arduino15/packages/rp2040/hardware/rp2040/3.9.5/cores/rp2040 -I/Users/sstaub/Library/Arduino15/packages/rp2040/hardware/rp2040/3.9.5/variants/rpipico /private/var/folders/vd/yv1mb7lx6gn7ymffgtjk6hx80000gn/T/arduino/sketches/0CD56E42A202B01F908E5D10B761265C/sketch/Compound_Literal.ino.cpp -o /private/var/folders/vd/yv1mb7lx6gn7ymffgtjk6hx80000gn/T/arduino/sketches/0CD56E42A202B01F908E5D10B761265C/sketch/Compound_Literal.ino.cpp.o
/Users/sstaub/Documents/Arduino/Compound_Literal/Compound_Literal.ino: In function 'void setup()':
/Users/sstaub/Documents/Arduino/Compound_Literal/Compound_Literal.ino:6:42: error: taking address of temporary array
    6 | #define VECTOR_ROOT_E131_DATA (uint8_t[]){0x00, 0x00, 0x00, 0x04}
      |                                          ^~~~~~~~~~~~~~~~~~~~~~~~
/Users/sstaub/Documents/Arduino/Compound_Literal/Compound_Literal.ino:18:37: note: in expansion of macro 'VECTOR_ROOT_E131_DATA'
   18 |         int equal2 = memcmp(vector, VECTOR_ROOT_E131_DATA, 4);
      |                                     ^~~~~~~~~~~~~~~~~~~~~
/Users/sstaub/Documents/Arduino/Compound_Literal/Compound_Literal.ino:6:42: error: taking address of temporary array
    6 | #define VECTOR_ROOT_E131_DATA (uint8_t[]){0x00, 0x00, 0x00, 0x04}
      |                                          ^~~~~~~~~~~~~~~~~~~~~~~~
/Users/sstaub/Documents/Arduino/Compound_Literal/Compound_Literal.ino:20:21: note: in expansion of macro 'VECTOR_ROOT_E131_DATA'
   20 |         memcpy(vec, VECTOR_ROOT_E131_DATA, 4);
      |                     ^~~~~~~~~~~~~~~~~~~~~

exit status 1

Compilation error: taking address of temporary array

Well, it appears to compile OK (ESP32-C3) if you wrap the "compound literal" in quotes. Does it do what you want, though ?
#define VECTOR_ROOT_E131_DATA "(uint8_t[]){0x00, 0x00, 0x00, 0x04}"

There's a discussion about it here: taking address of temporary array

Why are you so averse to declaring space for this little array?

Thank you for that hint. But I don't know why it is necessary, is it a GCC problem?
EDIT: This doesn't work. Yes you can compile but the content of the array is now completely wrong.

Not really a surprise - you are passing a string literal - the compiler is not trying to parse it as an array declaration.

In C, compound literals are allowed, and you can create temporary arrays but you cannot take the address of a temporary array because they are not stored in a persistent location.

In C++, compound literals are not part of the language.

But you can do it with clang compiler.

OK. I see why it compiled when in quotes. I regretably looked no further.
This appears to work:
#define VECTOR_ROOT_E131_DATA (const uint8_t *)((const uint8_t[]){0x00, 0x00, 0x00, 0x04})
However, I'm sure that @J-M-L's comment should not be ignored.

EDIT

or even this:
#define VECTOR_ROOT_E131_DATA (const uint8_t[]){0x00, 0x00, 0x00, 0x04}

The last example works as expected.

The const might make it a permanent array and then you can get its address

"static const" ?

Somewhere in flash where it can be addressed on the right architecture