[NSRCA-discussion] Chapter-12 computer science.
Matthew Frederick
mjfrederick at cox.net
Tue Jul 3 21:39:35 AKDT 2007
Oh yeah... and I can't remember ever programming in 8-bits...
----- Original Message -----
From: "Duane Beck" <duane.e.beck at comcast.net>
To: "NSRCA Mailing List" <nsrca-discussion at lists.nsrca.org>
Sent: Wednesday, July 04, 2007 12:16 AM
Subject: Re: [NSRCA-discussion] Chapter-12 computer science.
> Depends on whether char basic type is 8-bit or larger. Most decent
> compilers should issue a warning for comparing with an integer constant
> out of range. Assuming default char type is 8-bit signed, when cnt is
> 127, cnt increments to -128 (by wrapping around adjacent two's
> complement values) and the loop continues unterminated. If default char
> type is 8-bit unsigned, it's still unterminated because after 255, cnt
> will increment to 0. So, in both conditions, cnt is always less than
> 256. Otherwise, if char is larger (16-bit), foo returns 256.
>
> Duane
>
> Martin X. Moleski, SJ wrote:
>> John Pavlick wrote:
>>> OK, what does this do?
>>
>>> char foo(void)
>>> {
>>> char cnt, num;
>>>
>>> for(cnt = 0, num = 0; cnt < 256; cnt++)
>>> {
>>> num++;
>>> }
>>> return num;
>>> }
>>
>>
>> Initializes cnt and num to 0.
>>
>> Increments cnt and num from 0 to 255
>> by passing through the for loop.
>>
>> Returns 255.
>>
>>
>> Marty
>> _______________________________________________
>> NSRCA-discussion mailing list
>> NSRCA-discussion at lists.nsrca.org
>> http://lists.nsrca.org/mailman/listinfo/nsrca-discussion
>>
>
> _______________________________________________
> NSRCA-discussion mailing list
> NSRCA-discussion at lists.nsrca.org
> http://lists.nsrca.org/mailman/listinfo/nsrca-discussion
More information about the NSRCA-discussion
mailing list