Re: Uninitialised fields in structures
- From: Ulrich Eckhardt <doomster@xxxxxxxx>
- Date: Mon, 31 Dec 2007 15:02:59 +0100
vippstar@xxxxxxxxx wrote:
On Dec 31, 12:58 pm, Ulrich Eckhardt <dooms...@xxxxxxxx> wrote:
[Not explicitly initialised fields of a struct that is partiallyThe standard doesn't say anything about initializing the rest members
initialised are implicitly initialised to zero. ]
Now, I'm pretty sure about the rule with the additional fields, but I'm
wondering nonetheless. Can someone confirm or deny whether t.len above is
initialised or not?
to 0.
Well, that's where a few others and I disagree with you. Also, the compiler
only warns but still does the initialisation.
Using gdb to determine whether a program is correct or not is bad
practise, as it is to run the program and come to a conclusion by the
output. Gdb is not a 'C99 tool'.
Well, surely it is not a way to prove that the program is correct C.
However, I have four different opinions on whether the program is buggy:
1. Compiler
The compiler said something was uninitialised, which often causes errant
runtime behaviour, in my case it would have lead to calling free() with a
pointer to a string literal. Of course that is not a proof, since
uninitialised storage can contain anything, including a very deterministic
value.
2. Running
Running the program didn't cause any runtime errors, as free()ing a string
literal usually does. Same uncertainty as above though, but glibc otherwise
correctly detects this error.
3. Valgrind
Typically valgrind doesn't care too much about C but operates directly on
the generated machine code. The fact that it detects use of uninitialised
memory was what first prompted me to wonder whether there was something
behind the warnings emitted by the compiler.
4. GDB (a debugger)
I used the debugger to manually shred the memory of the variable that was
claimed to be not initialised. I observed that code was executed to lateron
initialise the variable to zero.
I'm aware that none of these tests are in any way mandated by any C
standard, but that's real life. ;)
Just for the interest of those that are reading this: the actual problem was
with my use of Valgrind. If I had paid a bit more attention to its output,
I would have seen that the errors are in fact detected in /lib/ld-2.3.6.so
and not in my executable. Actually using an uninitialised struct in my code
also causes it to be detected and reported as occurring in my code, so the
compiler output can be taken as "just a [stupid] warning".
Uli
.
- Follow-Ups:
- Re: Uninitialised fields in structures
- From: user923005
- Re: Uninitialised fields in structures
- References:
- Uninitialised fields in structures
- From: Ulrich Eckhardt
- Re: Uninitialised fields in structures
- From: vippstar
- Uninitialised fields in structures
- Prev by Date: Re: Bandwidth stealing
- Next by Date: How to deal with big-size files??
- Previous by thread: Re: Uninitialised fields in structures
- Next by thread: Re: Uninitialised fields in structures
- Index(es):
Relevant Pages
|