• zerofk@lemmy.zip
    link
    fedilink
    arrow-up
    2
    ·
    4 days ago

    Don’t blame this on gcc or the library/function author - it is 100% user (i.e. programmer) error. Uninitialised memory of any type is undefined behaviour in the C and C++ abstract machine. That means optimising compilers can assume it does not exist.

    For example, the compiler could see that your ‘b’ is never initialised. Therefore, using it would be undefined behaviour. So, the optimiser can assume it is never used, and it is as if that code simply does not exist: the behaviour you saw.

    I’m not saying that is what happened, nor that it will always happen, but it is a possibility.