re: The uninitialized variable anathema: non-deterministic C++ VIEW POST

re: extern void sys_fcn(int* handle); void fcn() { int a; sys_fcn(&a) } In that case, there is no way for the compiler/optimizer to know...

Yes, it's easy to find situations where the optimizer cannot optimize code. This doesn't discount the fact that in many cases it can.

I can't imagine a situation where the initialization cost in this type of code would be significant though. The overhead of calling the function, and the sub-function are probably more. And if there's any actual memory access involved, the pipelining of the CPU may render the init negligable.

That code also has the problem of a person being unable to determine whether it is correct. Without looking at the documentation for sys_fcn, you cannot tell if you should have initalized that variable or not.

As I said, in the cases where this is truly a cost problem (and they do exist), you could annotate it:

int a = undefined;

Or something like that.

code of conduct - report abuse