Article View: comp.lang.c.moderated
Article #2170Re: Evil C Contests
From: Stan Ryckman
Date: Mon, 04 Mar 1996 04:15
Date: Mon, 04 Mar 1996 04:15
38 lines
1626 bytes
1626 bytes
In article <4h75a2$4l6@solutions.solon.com>,
J. Kanze <kanze@gabi-soft.fr> wrote:
[...]
>The real portability problem is what will happen on a machine where
>sizeof( int ) == sizeof( char ). And if INT_MAX == CHAR_MAX. To tell
>the truth, I'm not even sure what the standard says about this: getchar
>returns an int in the range of 0...UCHAR_MAX, but UCHAR_MAX won't fit in
>an int.
>
>No matter what the standard says, getting the end condition of the
>output loop right is going to be tricky, since UCHAR_MAX + 1 == 0.
>Thus:
>
> for ( i = 0 ; i < UCHAR_MAX + 1 ; i ++ )
>
>doesn't execute the loop at all, and
>
> for ( i = 0 ; i <= UCHAR_MAX ; i ++ )
>
>is an infinite loop.
Perhaps this should be merged with the (IMHO rather silly) thread on
using or not using break within loops.
for ( i = 0 ; ; i ++ ) {
/* stuff */
if ( i == UCHAR_MAX )
break;
}
fits the bill just fine. And now we don't even have to try and figure
out whether i overflowing causes undefined behaviour or not.
Cheers,
Stan.
--
Stan Ryckman (stanr@tiac.net) (new e-mail address)
Technical Details
Message-ID:
<4hdqoe$8rl@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailReferences:
<4fu7pp$94q@solutions.solon.com> <4gfaki$1uc@solutions.solon.com> <4ghnp2$djn@solutions.solon.com> <4h75a2$4l6@solutions.solon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail From: stanr@tiac.net (Stan Ryckman) Newsgroups: comp.lang.c.moderated Subject: Re: Evil C Contests Date: 3 Mar 1996 22:15:10 -0600 Organization: Amber & Sneakers Fan Club Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4hdqoe$8rl@solutions.solon.com> References: <4fu7pp$94q@solutions.solon.com> <4gfaki$1uc@solutions.solon.com> <4ghnp2$djn@solutions.solon.com> <4h75a2$4l6@solutions.solon.com> NNTP-Posting-Host: solutions.solon.com