G
Guest
Given this code
void test(int a, int b, char * c) {
long d;
d = a + b;
memcpy(c, &d, sizeof(d));
}
Apart from having its address taken d is unused. Is a compiler at liberty
to optimize away the assignment to d?
Should taking the address of d do anything more than ensure storage is
allocated for it?
I have searched around and can't seem to find anything which defines what a
compiler is required to do with the above example.
TIA.
void test(int a, int b, char * c) {
long d;
d = a + b;
memcpy(c, &d, sizeof(d));
}
Apart from having its address taken d is unused. Is a compiler at liberty
to optimize away the assignment to d?
Should taking the address of d do anything more than ensure storage is
allocated for it?
I have searched around and can't seem to find anything which defines what a
compiler is required to do with the above example.
TIA.