#Does `int` preserve the size?

7 messages · Page 1 of 1 (latest)

short shard
#

lets say i have the following

typedef struct STRUCT_FOO {
    int a;
} foo;

void main() {
    long long x = do_something_large();
    foo f = { x };
}

will f.a still work as a long long, or is it now 32 bit?

winged oracleBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

dusk wigeon
#

when creating f, x is narrowed to the size of an int, so the value might not be preserved

#

it doesn't actually matter whether the int is in a struct or not, you would get the same effect with

long long x = do_something_large();
int f = x;
#

your compiler can warn you when a narrowing conversion happens, but only when compiling as C++

#

clang-tidy might catch it otherwise, not sure

short shard
#

!solved