c++ - Initializing union member in initializer list without narrowing -
in following code,
typedef unsigned long col24; inline col24 makergb24(int r, int g, int b) { return ...; } struct blitdata { union { int flags, stretch; col24 luminance; }; // (other members) }; int main() { blitdata blitdata = { makergb24(0, 0, 0), // ... }; } why first initializer in initializer list of blitdata give following error:
non-constant-expression cannot narrowed type
col24(akaunsigned long)intin initializer list
why compiler trying initialize int member of union initializer type col24 instead of using initialize col24 member?
the compiler suggests static_cast result of makergb24 int, result in unwanted narrowing.
how can luminance member correctly initialized using result of makergb24 in initializer list?
edit: blitdata should stay pod.
this apparently nonstandard gcc extension, you're after:
blitdata blitdata = { luminance: makergb24(0,0,0), }; if that's no you, suspect assigning afterwards way.
Comments
Post a Comment