I have the following code:
So you see that the x member is of short type but func returns an int, not a short. Would there be a problem with this code?Code:typedef struct X { const short x; } X; int func(void) { X x = { 3 }; return x.x; }
I have the following code:
So you see that the x member is of short type but func returns an int, not a short. Would there be a problem with this code?Code:typedef struct X { const short x; } X; int func(void) { X x = { 3 }; return x.x; }
Well putting const inside your struct makes it a tad inconvenient to use.
From a type point of view, nothing particular stands out.
There's never an issue from going from short to int because all values of short are guaranteed to fit inside an int.
Some compilers might give you a warning, but I dont think it will affect the results.
I am a little puzzled here, why do use const in your data structure?
The original code is written by somebody who uses const a lot, just to express that vars cant be changed. My own opinion would be to mostly use const for pointers really.Originally Posted by Afrinux