PROGMEM on compound-literal arrays
"Paul \"LeoNerd\" Evans" <[email protected]> Sun, 30 Oct 2016 11:43:38 +0000
| Newsgroups | gmane.comp.hardware.avr.gcc |
|---|---|
| Message-ID | <[email protected]> |
((TLDR: PROGMEM on compound-literal arrays is silently ignored.
Please either implement or make it a noisy warning/error.))
If I define a function that takes a byte array, e.g.
void i2c_write(size_t len, const uint8_t *data);
I find it nice to be able to call that with compound-literal arrays
inline:
i2c_write(4, (const uint8_t[]){0x10, 0x20, 0x30, 0x40});
((The reason I'm using this inline notation rather than a static
declaration made elsewhere is that my data in fact comes from a
build-time translation step, and most of the arguments to the function
call are embedded with an #include directive to embed the data in the
source code.))
If I want to store the data in PROGMEM instead and write a _P version,
then this syntax won't do:
i2c_write_P(4, (const PROGMEM uint8_t[]){0x10, 0x20, 0x30, 0x40});
While it does parse and compile successfully, the data doesn't end in
in PROGMEM, so the pgm_read_byte() function doesn't find it, and
returns junk. There's no compile-time warning or error that it hasn't
honoured it though, so debugging this failure can be hard.
The following syntax does work as an alternative:
i2c_write_P(4, ({
static const PROGMEM uint8_t data[] = {0x10, 0x20, 0x30, 0x40};
data;
}));
I.e. a statement-expression that embeds a static PROGMEM declaration
and yields it.
Would it be possible to make the former syntax work though?
--
Paul "LeoNerd" Evans
[email protected] | https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/ | https://www.tindie.com/stores/leonerd/
_______________________________________________
AVR-GCC-list mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/avr-gcc-list
signature.asc
(application/pgp-signature, 181 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iEYEARECAAYFAlgV3OoACgkQvLS2TC8cBo0mWQCg+JeiSC+8PrtfxV0khsZQav7Q wh8An3qjzWBo19m6vI9soU0NyxquGrWF =w0ZQ -----END PGP SIGNATURE-----