D
Dave Thompson
I assume you mean _simple, scalar, unaliased_ automatic variables.In <[email protected]> jacob navia <[email protected]> writes:
You are naive. Most compilers can detect most attempts to read from
uninitialised memory, when automatically allocated. Statically allocated
memory is always initialised and, for dynamically allocated memory, there
is always calloc.
Which may well be "most" cases, if only because use of such variables
is the most common case of object use.
But there are many uses of uninitialized automatic memory which cannot
(practically, or at all) be detected at compile time:
{
int a, b = 0, *p;
p = some computation that might be &a or &b
*p = 1;
a; // initialized?
}
{
int x[10], i;
for( i = 0; i < 5; i++ ) x = i;
i = some computation that might be < 5 or >= 5
x; // initialized?
}
etc. I do sometimes, if there is any significant complexity to the
logic, default-fill such variables so at least my bugs are Bohr-ing.
- David.Thompson1 at worldnet.att.net