On Apr 20, 11:59 pm, Barry Schwarz <(EMail Removed)> wrote:
> On Sun, 20 Apr 2008 15:21:23 0700 (PDT), Robert Gamble
>
>
>
> <(EMail Removed)> wrote:
> >On Apr 20, 2:28 pm, Barry Schwarz <(EMail Removed)> wrote:
> >> On Sun, 20 Apr 2008 04:18:56 0700 (PDT), Tomás Ó hÉilidhe
>
> >> <(EMail Removed)> wrote:
>
> >> >There are a few guarantees I exploit in the C Standard. For instance,
> >> >I might write
>
> >> > (unsigned)1
>
> >> >to get the maximum value for an unsigned integer.
>
> >> The standard guarantees that values for unsigned integers behave
> >> nicely when they wrap in either direction. However, your code will
> >> not work for an integer type wider than int. For C89 you probably
> >> need (unsigned long) 1L and for C99 (unsigned long long) 1LL.
>
> >What makes you think that?
>
> For sake of discussion, let us assume a 16 bit int and a 32 bit long
> and the common UINT_MAX and ULONG_MAX for these sizes.
>
> The statement
> unsigned long x = (unsigned)1;
> will set x to 65535 (the value of the right hand side) which is
> 0x0000ffff, hardly the maximum value for this unsigned long.
I certainly agree that (unsigned) 1 is not going to yield ULONG_MAX.
I took your original comment to imply that (unsigned long) 1 would
not produce the desired results without the L suffix, that is where my
objection stemmed from.

Robert Gamble
