Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: does 0<(unsigned short)0x8000 hold? |
| Date | 2012-03-27 12:15 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <4F71E7AF.7000500@verizon.net> (permalink) |
| References | <4f71cf85$0$21948$426a74cc@news.free.fr> |
On 03/27/2012 10:32 AM, Francois Grieu wrote:
> I just tested my code for portability problems on systems
> where int is 16-bit, and found one such system where
>
> #include <stdio.h>
> int main(void)
> {
> printf("%d\n", 0<(unsigned short)0x8000 );
> return 0;
> }
>
> outputs 0. If I change 0< to 0u<, the output is 1.
>
> Is that a bug in this compiler, w.r.t. C99?
INT_MAX is allowed to be as low as 0x7FFF, and that's presumably true on
a 16-bit system (though there's always been a lot of debate about what
"N-bit system" really means). If so, conversion of (unsigned
short)0x8000 to int would produce a negative value unless int has a
sign-and-magnitude type. But if INT_MAX is 0x7FFF, then (unsigned
char)0x8000 must be promoted to "unsigned int", rather than "int"
(6.3.1.1p2), and therefore 0 must also be converted to unsigned int,
before evaluating the expression. As a result that expression would be
equivalent to 0U < 0x8000U, which is still guaranteed to have a value of
1. I'd say this is a bug in the compiler.
> As an aside, 6.5.8p2 puzzles me; it reads:
> "One of the following shall hold:
> — both operands have real type;
> — both operands are pointers to qualified or unqualified versions
> of compatible object types; or
> — both operands are pointers to qualified or unqualified versions
> of compatible incomplete types.
> (..)"
>
> Would my example imply conversion to *real*, at least conceptually ?!
"The integer and real floating types are collectively called
real types." (6.2.5p17), therefore no conversion to a real type is
required. As a result, the usual arithmetic conversions require that the
integer promotions be applied to both operands (6.3.1.8p1).
> As an aside of the aside, I do not understand the third option in
> the constraint, ...
You're referring to "both operands [of a relational operator] are
pointers to qualified or unqualified versions of compatible incomplete
types."? I think the trickiest concept used in that sentence is
"pointers to ... compatible incomplete types". Is that what you're
having trouble with? Each of the following declarations defines a
pointer to an incomplete type:
int (*p_incomplete_array)[];
struct flexible_array
{
size_t count;
int member[];
} *pfa;
// No definition provided for struct my_struct
struct my_struct *pms;
void *pv;
> ... and it has been removed in N1570.
I can confirm that it has been removed. The implication would seem to be
that it's no longer possible to compare pointers to incomplete types for
relative order. I find this surprising. Am I misunderstanding it? If not
was it deliberately removed, or an accident? If deliberate, what was the
rationale for doing so?
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
does 0<(unsigned short)0x8000 hold? Francois Grieu <fgrieu@gmail.com> - 2012-03-27 16:32 +0200
Re: does 0<(unsigned short)0x8000 hold? Harald van Dijk <haraldvdijk@gmail.com> - 2012-03-27 09:09 -0700
Re: does 0<(unsigned short)0x8000 hold? James Kuyper <jameskuyper@verizon.net> - 2012-03-27 12:15 -0400
Re: does 0<(unsigned short)0x8000 hold? Francois Grieu <fgrieu@gmail.com> - 2012-03-27 18:54 +0200
Re: does 0<(unsigned short)0x8000 hold? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-03-27 17:23 +0100
Re: does 0<(unsigned short)0x8000 hold? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-03-27 20:12 +0100
Re: does 0<(unsigned short)0x8000 hold? James Kuyper <jameskuyper@verizon.net> - 2012-03-27 15:32 -0400
Re: does 0<(unsigned short)0x8000 hold? Harald van Dijk <haraldvdijk@gmail.com> - 2012-03-27 12:47 -0700
Re: does 0<(unsigned short)0x8000 hold? James Kuyper <jameskuyper@verizon.net> - 2012-03-27 16:11 -0400
Re: does 0<(unsigned short)0x8000 hold? Tim Rentsch <txr@alumni.caltech.edu> - 2012-03-27 10:32 -0700
Re: does 0<(unsigned short)0x8000 hold? Francois Grieu <fgrieu@gmail.com> - 2012-03-28 15:08 +0200
Re: does 0<(unsigned short)0x8000 hold? Philipp Klaus Krause <pkk@spth.de> - 2012-03-28 09:07 +0200
Re: does 0<(unsigned short)0x8000 hold? Francois Grieu <fgrieu@gmail.com> - 2012-03-28 16:15 +0200
Re: does 0<(unsigned short)0x8000 hold? Kaz Kylheku <kaz@kylheku.com> - 2012-03-28 14:26 +0000
Re: does 0<(unsigned short)0x8000 hold? Peter Nilsson <airia@acay.com.au> - 2012-03-27 23:22 -0700
csiph-web