[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: uninitializing constructor

From: david
Subject: Re: uninitializing constructor
Date: Fri, 6 Oct 2006 19:13:00 +0000 (UTC)


I'd like to know whether g++ can detect a member variable which is not
initialized (on purpose) by the constructor.

Easier with a simple example (the class is supposed to be a fixed point

class A
       int my_value;
       A (int init)      { my_value = init; }
       A () {}
       A (const A& init) { my_value = init.my_value; }
       A& operator = (int scalar) { my_value = scalar << 8; }

int main (void)
       int p, q;
       A x, y;

       p = q;
       y = x;

g++ complains about q beeing used but not initialized, is there a way for it
to complain about x too ?
I tried the options -O -Wall -Wextra.

(yes I could put 0 in the constructor, but code size is critical in the
embedded environment I use, and I'm curious too :-)

I also tried "A () const {}" but it is refused.

I know from comp.lang.c++ that this is not a c++standard request to do so,
but there are always some interesting stuff in gcc that I don't know :-)

Thanks for any information,


reply via email to

[Prev in Thread] Current Thread [Next in Thread]