Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
Fast-Nop2691878dIf it's a global pointer, it is actually a null pointer if NULL is defined as 0, which it is everywhere.
An uninitialised pointer from the stack or in malloc'ed memory is undefined behaviour if dereferenced, so the compiler can do anything. Usually optimising large parts of the program away to have still nonsensical behaviour but with maximum performance.
Demolishun679678dnullptr, you animal ;-)
Geoxion50478d@Fast-Nop even that's not entirely true. I've worked on a platform that had a ram-wiping sleep cycle. The ram was turned off to save power.
When the device would wake up, all uninitialized pointers were not assigned any new value so they would contain garbage.
This was however with an older version of GCC (5.4?), so maybe that wasn't playing nice.
Still, always initialize!
Fast-Nop2691878d@Geoxion Well yeah, if the hardware wipes out memory underneath the program, nothing works anymore. What I meant was that global non-initialised variables in C/C++ are initialised to 0 at program start so that no explicit initialisation is required. Once execution reaches main(), this must have been done, or the runtime implementation is buggy.
Demolishun679678d@Fast-Nop And code mixed with multiple compilation units and constructors that operate on globals lists that init part of the params of items in that list...
Other devs: It works on Linux.
me: It was luck of the draw that it worked. It changed the order on Windows. Why are you init-ing params that the OS zeros out anyway?
Other devs: I don't know...
me: I am taking out the constructor. This code needs a redesign at some point.
Other devs: okay
xjose97x14Just saw a variable in C named like this: long time_ago; //in a galaxy far away I laughed no stop.
Unskipp24So this happened last night... Gf: my favorite bra is not fitting me anymore Me: get a new one ? Gf: but it ...
sam966912Hats off to this lady .... I would have just flipped the machine