What the hell gcc?
-
float mpu6886::inv_sqrt(float x) {
float halfx = 0.5f * x;
float y = x;
// required, or "y is unintialized":
#pragma GCC diagnostic ignored "-Wuninitialized"
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
long i = *(long *)&y;
i = 0x5f3759df - (i >> 1);
y = *(float *)&i;
#pragma GCC diagnostic warning "-Wuninitialized"
#pragma GCC diagnostic warning "-Wstrict-aliasing"
y = y * (1.5f - (halfx * y * y));
return y;
}Tell me how y is uninitialized? This isn't the first time I've encountered this. :~
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
-
float mpu6886::inv_sqrt(float x) {
float halfx = 0.5f * x;
float y = x;
// required, or "y is unintialized":
#pragma GCC diagnostic ignored "-Wuninitialized"
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
long i = *(long *)&y;
i = 0x5f3759df - (i >> 1);
y = *(float *)&i;
#pragma GCC diagnostic warning "-Wuninitialized"
#pragma GCC diagnostic warning "-Wstrict-aliasing"
y = y * (1.5f - (halfx * y * y));
return y;
}Tell me how y is uninitialized? This isn't the first time I've encountered this. :~
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
Ah, the fast inverse square root. Mind boggling code, I have not spent the time trying to work out how it works. Without the code they commented then y would very likely have a terrible guesstimate and the function would be inaccurate, so y has not been 'initialised' with a good first guess. Weak definition of initialised, but some grain of logic there.
-
Ah, the fast inverse square root. Mind boggling code, I have not spent the time trying to work out how it works. Without the code they commented then y would very likely have a terrible guesstimate and the function would be inaccurate, so y has not been 'initialised' with a good first guess. Weak definition of initialised, but some grain of logic there.
but i explicitly assign y to x. :confused:
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
-
but i explicitly assign y to x. :confused:
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
Ah, sorry, I completely misread your original post. I would guess the error/warning is because you can not guarantee the sizes of long and float will be the same between C++ implementations. Just a stab in the dark though, and it seems like a strange error for that.
-
float mpu6886::inv_sqrt(float x) {
float halfx = 0.5f * x;
float y = x;
// required, or "y is unintialized":
#pragma GCC diagnostic ignored "-Wuninitialized"
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
long i = *(long *)&y;
i = 0x5f3759df - (i >> 1);
y = *(float *)&i;
#pragma GCC diagnostic warning "-Wuninitialized"
#pragma GCC diagnostic warning "-Wstrict-aliasing"
y = y * (1.5f - (halfx * y * y));
return y;
}Tell me how y is uninitialized? This isn't the first time I've encountered this. :~
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
-
float mpu6886::inv_sqrt(float x) {
float halfx = 0.5f * x;
float y = x;
// required, or "y is unintialized":
#pragma GCC diagnostic ignored "-Wuninitialized"
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
long i = *(long *)&y;
i = 0x5f3759df - (i >> 1);
y = *(float *)&i;
#pragma GCC diagnostic warning "-Wuninitialized"
#pragma GCC diagnostic warning "-Wstrict-aliasing"
y = y * (1.5f - (halfx * y * y));
return y;
}Tell me how y is uninitialized? This isn't the first time I've encountered this. :~
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
-
float mpu6886::inv_sqrt(float x) {
float halfx = 0.5f * x;
float y = x;
// required, or "y is unintialized":
#pragma GCC diagnostic ignored "-Wuninitialized"
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
long i = *(long *)&y;
i = 0x5f3759df - (i >> 1);
y = *(float *)&i;
#pragma GCC diagnostic warning "-Wuninitialized"
#pragma GCC diagnostic warning "-Wstrict-aliasing"
y = y * (1.5f - (halfx * y * y));
return y;
}Tell me how y is uninitialized? This isn't the first time I've encountered this. :~
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
-
no std available here
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
-
float mpu6886::inv_sqrt(float x) {
float halfx = 0.5f * x;
float y = x;
// required, or "y is unintialized":
#pragma GCC diagnostic ignored "-Wuninitialized"
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
long i = *(long *)&y;
i = 0x5f3759df - (i >> 1);
y = *(float *)&i;
#pragma GCC diagnostic warning "-Wuninitialized"
#pragma GCC diagnostic warning "-Wstrict-aliasing"
y = y * (1.5f - (halfx * y * y));
return y;
}Tell me how y is uninitialized? This isn't the first time I've encountered this. :~
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
-
Visual C++ does not complain about anything with that code. I think this qualifies as a bug.
"They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"
It very well could be. I've encountered this error in error before, I think? I'm just really hesitant to file a bug against a compiler because I feel like they know a hell of a lot more about C and C++ than I do.
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
-
It very well could be. I've encountered this error in error before, I think? I'm just really hesitant to file a bug against a compiler because I feel like they know a hell of a lot more about C and C++ than I do.
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
What machine are you targeting, and what are the sizes of
float
andlong*
?: If you compile this as 32 bit with gcc, you do not get any warnings. Theory: you're compiling in 64 bit modesizeof(float)
= 4 andsizeof(long*)
= 8. So what the compiler is trying to tell you is thatlong i = *(long*)&y
the conversion of the float to a pointer, half the bytes are uninitialized. My theory anyway."A little song, a little dance, a little seltzer down your pants" Chuckles the clown
-
What machine are you targeting, and what are the sizes of
float
andlong*
?: If you compile this as 32 bit with gcc, you do not get any warnings. Theory: you're compiling in 64 bit modesizeof(float)
= 4 andsizeof(long*)
= 8. So what the compiler is trying to tell you is thatlong i = *(long*)&y
the conversion of the float to a pointer, half the bytes are uninitialized. My theory anyway."A little song, a little dance, a little seltzer down your pants" Chuckles the clown
it's 32-bit GCC My processor can handle 64-bit numbers, but not as a native word. Edit: I'm not sure
long
isn't 64 bit on this platform, but I've always usedlong long
for that. My CPU will not handle 128-bit words under any circumstances.Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
-
it's 32-bit GCC My processor can handle 64-bit numbers, but not as a native word. Edit: I'm not sure
long
isn't 64 bit on this platform, but I've always usedlong long
for that. My CPU will not handle 128-bit words under any circumstances.Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
-
The issue would arise if the size of a float is less than the size of a pointer. Maybe just ask the compiler to what sizeof(float) and sizeof(void*) return?
"A little song, a little dance, a little seltzer down your pants" Chuckles the clown
Thanks. I'll look into it as time and motivation allows. :) Edit: Turns out i had a project open so it was easy enough to check
sizeof(float): 4
sizeof(long*): 4I checked sizeof long* just to be certain
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
-
Thanks. I'll look into it as time and motivation allows. :) Edit: Turns out i had a project open so it was easy enough to check
sizeof(float): 4
sizeof(long*): 4I checked sizeof long* just to be certain
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
-
Well, not that then :( Seemed like a good answer at the time. Maybe it's just the type punning that's baffling the compiler?
"A little song, a little dance, a little seltzer down your pants" Chuckles the clown
That's my theory, but I'm uncomfortable with it if nothing else because a) I hate assuming compiler bugs. So often it's some effing intricacy of the C or C++ language that is at play, rather than the compiler in error. b) You'd think it would have been found and fixed. Like I said, this isn't the first time I've run into it. The last time was a lot more innocuous - no type aliasing or fudging like that. it was an
enum struct
type declared as a local variable and initialized at declaration time. :confused: :rolleyes: I'd dig up the old example if i could, but I ended up working around it in order to get the warnings out of my code without using compiler specific pragmas. Edit: Duh. I am not using the latest GCC. I didn't think about that. Could easily be a bug.Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
-
That's my theory, but I'm uncomfortable with it if nothing else because a) I hate assuming compiler bugs. So often it's some effing intricacy of the C or C++ language that is at play, rather than the compiler in error. b) You'd think it would have been found and fixed. Like I said, this isn't the first time I've run into it. The last time was a lot more innocuous - no type aliasing or fudging like that. it was an
enum struct
type declared as a local variable and initialized at declaration time. :confused: :rolleyes: I'd dig up the old example if i could, but I ended up working around it in order to get the warnings out of my code without using compiler specific pragmas. Edit: Duh. I am not using the latest GCC. I didn't think about that. Could easily be a bug.Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
-
That's my theory, but I'm uncomfortable with it if nothing else because a) I hate assuming compiler bugs. So often it's some effing intricacy of the C or C++ language that is at play, rather than the compiler in error. b) You'd think it would have been found and fixed. Like I said, this isn't the first time I've run into it. The last time was a lot more innocuous - no type aliasing or fudging like that. it was an
enum struct
type declared as a local variable and initialized at declaration time. :confused: :rolleyes: I'd dig up the old example if i could, but I ended up working around it in order to get the warnings out of my code without using compiler specific pragmas. Edit: Duh. I am not using the latest GCC. I didn't think about that. Could easily be a bug.Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
As far as I am concerned, the fact that you have this line :
float y = x;
which is clearly initializing the variable qualifies it as a bug. I can not conceive a situation where that is not a bug.
"They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"
-
I get the same warning with gcc-14.1.0, and with x86-64 gcc-trunk over at the compiler explorer, so it's not been fixed so far.
"A little song, a little dance, a little seltzer down your pants" Chuckles the clown
I didn't think of trying godbolt. I'm really distracted rn on the phone w/ an old friend.
Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
-
That's my theory, but I'm uncomfortable with it if nothing else because a) I hate assuming compiler bugs. So often it's some effing intricacy of the C or C++ language that is at play, rather than the compiler in error. b) You'd think it would have been found and fixed. Like I said, this isn't the first time I've run into it. The last time was a lot more innocuous - no type aliasing or fudging like that. it was an
enum struct
type declared as a local variable and initialized at declaration time. :confused: :rolleyes: I'd dig up the old example if i could, but I ended up working around it in order to get the warnings out of my code without using compiler specific pragmas. Edit: Duh. I am not using the latest GCC. I didn't think about that. Could easily be a bug.Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix