|
From: ragnar s. <rag...@po...> - 2003-07-10 11:24:47
|
Hello!
I have two C files:
---------------------
#include <stdio.h>
void
func_one (int len)
{
int c;
float e;
e = 0;
c = 0;
while(c < len)
{
e = e * 0.7;
c++;
}
}
--------------------
#include <stdio.h>
void
func_one (int size);
void
func_two (int len)
{
int c;
float e;
e = 0;
c = 0;
while(c < len)
{
e = e * 0.7;
c++;
}
}
int
main (int argc, char **argv)
{
func_one (1024);
func_two (1024);
exit(0);
}
-------------------
These two I compile with:
gcc -g -O3 -Wall -c func.c -o func.o
gcc -g -O3 -Wall prog.c -o prog func.o
Now when I run valgrind I get:
$ valgrind -v --gdb-attach=yes ./prog
==4808== Memcheck, a.k.a. Valgrind, a memory error detector for x86-linux.
==4808== Copyright (C) 2002, and GNU GPL'd, by Julian Seward.
==4808== Using valgrind-1.9.5, a program instrumentation system for x86-linux.
==4808== Copyright (C) 2000-2002, and GNU GPL'd, by Julian Seward.
==4808== Startup, with flags:
==4808== --suppressions=/usr/local/lib/valgrind/default.supp
==4808== -v
==4808== --gdb-attach=yes
==4808== Reading suppressions file: /usr/local/lib/valgrind/default.supp
==4808== Estimated CPU clock rate is 1001 MHz
==4808==
==4808== Reading syms from /prog
==4808== Reading syms from /lib/ld-2.2.5.so
==4808== object doesn't have any debug info
==4808== Reading syms from /usr/local/lib/valgrind/vgskin_memcheck.so
==4808== Reading syms from /usr/local/lib/valgrind/valgrind.so
==4808== Reading syms from /lib/libc-2.2.5.so
==4808== object doesn't have any debug info
==4808== Use of uninitialised value of size 8
==4808== at 0x804843D: func_one (func.c:11)
==4808== by 0x804841A: main (prog.c:25)
==4808== by 0x4023214E: __libc_start_main (in /lib/libc-2.2.5.so)
==4808== by 0x8048330: (within /prog)
==4808==
==4808== ---- Attach to GDB ? --- [Return/N/n/Y/y/C/c] ----
...
If i remark func_one() inside main,
so only func_two() will be called, then
valgrind will not show any errors.
Also if I change the line in func_one() to:
e = e * (float)0.7;
valgrind will also not complain about errors.
So I wonder why I need this cast, and why
valgrind tell me about an error only if the
function is kept in a separate file, and
not shown when the function is brought inside
the main() file.
Thanks for any help on this.
Ragnar
___________________________________________________
How many satellites does the planet Uranus have? 0, 5 or 15?
Find out at postmaster.co.uk
http://www.postmaster.co.uk/cgi-bin/meme/quiz.pl?id=211
|
|
From: Igmar P. <mai...@jd...> - 2003-07-10 12:19:22
|
> So I wonder why I need this cast, and why > valgrind tell me about an error only if the > function is kept in a separate file, and > not shown when the function is brought inside > the main() file. Valgrind 1.9.6 doesn't give errors, I suggest you upgrade. Igmar |