Re: self-confidence of compiler



On May 8, 5:06 pm, Jon Skeet [C# MVP] <s...@xxxxxxxxx> wrote:
Peter Duniho <NpOeStPe...@xxxxxxxxxxxxxxxx> wrote:
<snip>
I do know that I don't recall my C++ code generating "this variable is
unassigned" errors, but that's probably due to the lack of *any* checking
as opposed to more correct checking.

I *seem* to remember that gcc had some checking like this, and
Microsoft's C compiler does with /Wall on, but it's not *hugely* smart
- it still complains at:

#include <stdio.h>

int main(void)
{
int x;
int y=1;
if (y==1)
{
x = 5;
}
printf ("%d", x);

}

Interestingly, the warning here talks about a "potentially
uninitialized local variable" - but if you remove the assignment in the
if statement, it turns the error into just "uninitialized local
variable".

<snip>
gcc, aCC (HP-UX), and Digital Mars all complain in some fashion about
uninitialized variables if you set the warning level high enough. I'd
have to do some tests as to what the exact messages are. I've had
issues in the dark past with static locals being used without being
initialized and the compiler not catching that.

Tim

.



Relevant Pages

  • Re: sigset_t and gcc
    ... > It compiles ok with 'gcc file.c', ... > It complains that 'sigset_t' is undeclared. ... > What options am I missing? ... > int main ...
    (comp.lang.c)
  • sigset_t and gcc
    ... It compiles ok with 'gcc file.c', ... It complains that 'sigset_t' is undeclared. ... int main ...
    (comp.lang.c)
  • Templates gcc 3.4
    ... I've just upgraded to gcc 3.4 resulting in problems in some template ... int main ... It complains about: ... also tried this modified code in gcc 3.3 resulting in the same problem. ...
    (comp.lang.cpp)
  • Re: data types
    ... Usually short is smaller than an int. ... Your compiler is either *really* old or broken or both. ... recommend either a version of gcc,, or Visual Studio ... Microsoft's Visual Studio Express has an onerous EULA). ...
    (comp.lang.c)
  • Re: stream io in c
    ... zero to 255, putchar'ing in the body of the loop, then redirecting output ... int main ... // gcc -o chars mkchars1.c ... This compiles but gcc warns of incompatible pointer types. ...
    (comp.lang.c)