Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #10379

Re: maximum value of int

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c
Subject Re: maximum value of int
Date Sat, 17 Sep 2011 17:25:33 +1200
Lines 24
Message-ID <9dipadFr5dU3@mid.individual.net> (permalink)
References <394fc242-c6ae-41ba-9861-6d4c88ec25b5@f17g2000yqh.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Trace individual.net B1DXsogzYhRcvi6Zgno6qQMaJt6Qgktgmh4gAZtr9HNOMC0v45
Cancel-Lock sha1:7v/rWtKWVa8cakXtRsayYQDpUyo=
User-Agent Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:1.9.2.9) Gecko/20101021 Lightning/1.0b2 Thunderbird/3.1.4
In-Reply-To <394fc242-c6ae-41ba-9861-6d4c88ec25b5@f17g2000yqh.googlegroups.com>
Xref x330-a1.tempe.blueboxinc.net comp.lang.c:10379

Show key headers only | View raw


On 09/17/11 05:07 PM, Stanley Rice wrote:
> Hello all
>
> I don't know it is appropriate to post such a short or easy question
> here. I couldn't understand some line of code abot maximum int value
> as below:
>
>      #define INT_MAX (((unsigned)-1)>>  1)
>
> The first time I saw it, I was confused why it could pass the
> examination of the compiler. I try to make a bit modification, say
>      #define INT_TEST ((unsigned) - 1)
> This time, the compiler also shuts its mouth, but when I try
>      #define INT_TEST (unsigned)
> The compiler begins to shout to me.
>
> I'm confused about why the type itself, i.e unsigned, could do
> subtration. And it could generate an integer. But when I leave the
> type alone, the compiler tries to stop me.

(unsigned)-1 is a cast, not a subtraction.

-- 
Ian Collins

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

maximum value of int Stanley Rice <heconghui@gmail.com> - 2011-09-16 22:07 -0700
  Re: maximum value of int Ian Collins <ian-news@hotmail.com> - 2011-09-17 17:25 +1200
    Re: maximum value of int Stanley Rice <heconghui@gmail.com> - 2011-09-17 00:47 -0700
      Re: maximum value of int Paul N <gw7rib@aol.com> - 2011-09-17 03:53 -0700
      Re: maximum value of int Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-09-17 12:17 +0100
      Re: maximum value of int Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2011-09-17 10:31 -0600
        Re: maximum value of int Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-09-17 19:51 +0100
      Re: maximum value of int Keith Thompson <kst-u@mib.org> - 2011-09-17 14:39 -0700
  Re: maximum value of int Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-17 07:51 -0400

csiph-web