15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


compiler note

Ghislain Lachapelle -- Ghislain.Lachapelle@Matrox.COM
Monday, February 05, 1996

Some of you are probably aware of this but it seems that MSVC 4.0 does not
have any way of checking for variables being used before they are
initialized, even though I seem to recall that the 2.x versions did this
check. This means that code like:

        int a;
        int b;

        a=b;

will quite happily compile. Most of the other compilers which I've used over
the last few years would have no trouble spotting this. If anyone has found
a way to check for these types of errors, please let us know.

///////////////////////////////////////////////////////////////////////
Ghislain Lachapelle(Ghislain.Lachapelle@matrox.com)

Ghislain Lachapelle, ext. 2495
Matrox Electronic Systems Ltd.
Imaging Group
1055 St-Regis Blvd.
Dorval, Quebec, Canada
H9P 2T4


(514) 685-7230, ext. 2495
////////////////////////////////////////////////////////////////////////




djw@arbortext.com
Tuesday, February 06, 1996

[Mini-digest: 3 responses]

[Moderator's note: Yes, I realize that this isn't MFC-specific, but
it seemed to me to be one of those things that's useful for us all
to know.  The answer is even more interesting, since this exact thing
came up for me yesterday, and I didn't know why it happened.]

>Some of you are probably aware of this but it seems that MSVC 4.0 does not
>have any way of checking for variables being used before they are
>initialized, even though I seem to recall that the 2.x versions did this
>check. This means that code like: ...

Did you turn on optimization?  I recall seeing a note, perhaps one of those
startup tips, about unitialized variables only being detected if optimization
was on.  Hence it's desirable to perform a release build now and then, even
if you're still in the development phase.

Dave  djw@arbortext.com


-----From: Brad Wilson 

> Some of you are probably aware of this but it seems that MSVC 4.0 does not
> have any way of checking for variables being used before they are
> initialized, even though I seem to recall that the 2.x versions did this
> check. This means that code like:

While it is often times helpful to have your compiler spot your mistakes,
a small change in coding style would have prevented this too:

(a) ensure variables have the smallest possible scope, to help spot errors
    like this one;
(b) use globals as infrequently as possible;
(c) never declare a variable without initializing it

To be honest, I was pretty surprised that MSVC didn't catch this.  But
catching things like this should be a last resort; you should _always_
code as though the compiler tells you nothing.

And -- of course -- there is the converse rule of: you should _always_
pay attention to _all_ the warnings that your compiler gives you, and
you should _always_ be using the maximum warning level.

One other possibility, if you've got code you need to check (ie, perhaps
you acquired some technology with poorly written code), is to get the
product "Lint".  While some people berate this for it's unbelievable
verbosity, it's a very helpful product.

(I have no financial ties to Lint or Microsoft)

Brad

--
class CBradWilson : public CWorldWatchProgrammingTeam {
  public:
    void GetInetAddr  ( CString& s ) { s = "bradw@exptech.com";      }
    void GetE164Addr  ( CString& s ) { s = "+1 (810) 620-9803";      }
    void GetURL       ( CString& s ) { s = "http://www.exptech.com"; }
    void GetDisclaimer( CString& s ) { s = "All I say is fact :-p";  }
};

//  LOTW:  "In my den of inequity, viciousness and subtelty, struggle to ease
//          the pain, struggle to find the sane; ignorance surrounding me"

-----From: Dicky Singh 

Use option /Og and compile a release build.=20

Quoting: "The compiler detects the use of un-initialized data only in =
optimized builds (/Og). So it's a good idea to do a release build =
occasionally."

// Dicky@Landmark.com




| Вернуться в корень Архива |