On Fri, 15 Aug 2008, Mike Kershaw wrote:
> On Fri, Aug 15, 2008 at 12:03:23PM -0400, lex wrote:
>>> The first, and all subsequent before a write, read operations.
>>> (compare, print, assign to another var, etc)
>>>
>>> -m
>>>
>>> --
>>> Mike Kershaw/Dragorn <[EMAIL PROTECTED]>
>>> GPG Fingerprint: 3546 89DF 3C9D ED80 3381 A661 D7B2 8822 738B BDB1
>>>
>>> Life is a whim of several billion cells to be you for a while.
>>>
>>
>> No, my program does not have any reads nor writes nor any other I/O.
>>
>> It has 45 uses of x. Only one or two use the variable without it having
>> been set first. Which ones are they?
>
> That doesn't really make any sense.
>
> The warning is generated for any read operations before the variable is
> set. Any operations AFTER the variable is assigned will NOT generate
> the warning in that function, since the content has now been
> initialized. If you do one read op and 44 write ops, you'll get the
> error for the first one. If you do 10 read ops before initialization,
> then the warning applies to the first 10. After you put a value in
> there, it's initialized, and the error is no longer applicable.
>
> Notice I said read *operation*. Anything that reads from the variable.
> if (x == 1) is a read operation. printf("%d", x); is a read operation.
> y = x; is a read operation. Reading the contents of an unitialized
> variable will generate that warning - it's got nothing to do with user
> or file i/o.
>
> Any uses of X before you assign a value to it are unitialized.
>
> While you can solve it by simply adding an init during the variable
> creation (int x = 0;) that won't solve the logic errors of using a
> variable that has no content before you put something into it.
>
> While there are some obtuse ways to make it so the variable really does
> have legit content in it and the compiler thinks it doesn't, it's
> generally a coding error.
>
> -m
>
> --
Yes, there may be 10 reads before it is set, and 20 therafter.
But which ones are the 10? The compiler does not give that information,
only the line number of where the variable is declared.
Lex
_______________________________________________
Mid-Hudson Valley Linux Users Group http://mhvlug.org
http://mhvlug.org/cgi-bin/mailman/listinfo/mhvlug
Upcoming Meetings (6pm - 8pm) MHVLS Auditorium
Jun 4 - Sqeak! and eToys
Jul 2 - KVM (Tenative)
Aug 6 - Zenos
Sep 3 - TBD