Uninitialized variables & Bounds runtime checking
Axel Freyn
axel-freyn@gmx.de
Wed Oct 6 09:44:00 GMT 2010
Hi Miguel,
On Wed, Oct 06, 2010 at 09:23:39AM +0200, Miguel Angel wrote:
> Â Â I've been searching about possible *run-time* checks that can be
> used with GCC, and after a little bit of investigation I discovered
> about -fbounds-check, but no others...
>
> Â -fbounds-check only apply to Fortran compiles or they work on C/C++ too?
>
> does exist some kind of flag for testing on unitialized variables
> (during runtime), in my case some problems arise when somebody leaves
> an unintialized C++ class attribute.
Maybe you can use "-Weffc++" -- this warns e.g. for un-initialized
attributes -- however,
- it generates MANY warnings, also from code in the standard library
- it will warn also when you assign a value in the constructor, but not
using initialization. The code:
class A{
A():x(0){}
A(const A&a){x=a.x;}
int x;
};
generates a warning for line 3: "warning: âA::xâ should be
initialized in the member initialization list"
And of course, that's only a compile time check.
I don't know any additional flags for gcc -- however: Do you know
"valgrind"? That's an independent program, which can be used to perform
checks for using of uninitialized memory on already compiled code -- it
will report the corresponding line in the source-code too.
Axel
More information about the Gcc-help
mailing list