Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
If 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. -
Geoxion9025y@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! -
@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.
-
@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
Related Rants
-
xjose97x19Just 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 ...
-
sam966911Hats off to this lady .... I would have just flipped the machine
Uninitialized pointer is not the same as NULL pointer !
Uninitialized pointer is not the same as NULL pointer !
Uninitialized pointer is not the same as NULL pointer !
Uninitialized pointer is not the same as NULL pointer !
rant
pointers
nullpointer
c++