Re:Tree traversal without recursion: the tree as a state mac...
by rocqua on Tuesday September 03, 2019 @03:47AM
(#20864422)
Hard to get this done properly in C I imagine. You're getting into UB the moment you start bit-fiddling with pointers I think.
[ Parent
| on HN ]
Re:Tree traversal without recursion: the tree as a state mac...
by vnorilo on Tuesday September 03, 2019 @04:10AM
(#20864545)
Not UB but rather implementation defined. The compiler will not do anything weird here, but you rely on platform behavior that's not specified by the C lang spec.
Re:Tree traversal without recursion: the tree as a state mac...
by PeCaN on Tuesday September 03, 2019 @03:53AM
(#20864461)
Nah, so long as you cast to an integer (preferably uintptr_t) before fiddling with it you're fine¹
―
¹ I think, but to be honest it's been some time since I really knew the arcane C rules and I'm not confident anymore
Re:Tree traversal without recursion: the tree as a state mac...
by Asooka on Tuesday September 03, 2019 @04:52AM
(#20864756)
Not UB in the slightest. You can take a pointer, cast it to uintptr_t, do whatever you want to that int, then cast it back to a pointer. It's only UB if the resulting pointer isn't valid or you cast it to the wrong type (and strict aliasing is enabled.