Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Type interchange |
| Date | 2011-12-02 13:49 -0800 |
| Organization | None to speak of |
| Message-ID | <ln7h2eod9d.fsf@nuthaus.mib.org> (permalink) |
| References | (7 earlier) <4ED7AB31.1010500@verizon.net> <ln62hzq5zh.fsf@nuthaus.mib.org> <jb991v$vfv$1@dont-email.me> <lnobvroive.fsf@nuthaus.mib.org> <4ED904D9.2070301@verizon.net> |
James Kuyper <jameskuyper@verizon.net> writes:
> On 12/01/2011 08:35 PM, Keith Thompson wrote:
>> James Kuyper <jameskuyper@verizon.net> writes:
> ...
>>> Keep in mind that if an implementation treats a 32-bit int and a 64-bit
>>> long as being compatible, it can't hide behind the clauses that give
>>> undefined behavior to code which treats them as compatible. I personally
>>> don't see how they could conform to those requirements, but if they did
>>> somehow manage to do so, I don't see any need for a warning except for
>>> purposes of writing portable code - and as a matter of QoI, I would
>>> consider providing such warnings to be essential.
>>
>> One question.
>>
>> Under what circumstances, if any, may a conforming implementation *not*
>> issue a diagnostic for the following program?
>>
>> int main(void) {
>> int *ip = 0;
>> long *lp = ip;
>> return 0;
>> }
>
> With the standard as currently written, I don't believe that 'int' and
> 'long' are required to be incompatible, thought they do have to be
> different types. If that's correct, then as you suggest, it implies that
> an implementation where they are compatible is not required to issue a
> diagnostic for such code. As a matter of QoI, such an implementation
> would be sufficiently bizarre that it should provide a warning anyway,
> but I don't think it would be fail to conform for that reason.
>
> However, they must actually be compatible: if you write any valid long
> value using *lp, and read it back using *ip, you must read the same
> value (and not cause any other problems as a side effect). How that
> could possibly be true in the particular case you mentioned, with a
> 32-bit int and a 64-bit long, I have no idea - but if someone figured
> out how to make it work, it would be a conforming implementation of C.
Do you believe that the committee *deliberately* left the
compatibility or incompatibility of int and long unspecified,
*and* failed to require implementations to document their choice?
Do you think they meant to allow implementations to make int and
long compatible even if they're of different sizes? If so, do you
think it made sense to do so?
I don't. I think they intended int and long to be incompatible in
all cases, but neglected to state explicitly that the definition
of "compatible types" is exhaustive. And I think that the only
*sensible* interpretation of what the standard says (even if it
fails to state it explicitly) is that two types are compatible if
and only if the standard says they are.
Similarly, I assume that 42 is an expression (even though the
definition of "expression" in 6.5p1 implies that it isn't),
that it's not an lvalue (even though the definition of "lvalue"
in 6.3.2.1p1 implies that it is), and that it has a value (even
though the definition of "value" in 3.17 implies that it doesn't).
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Type interchange Edward Rutherford <edward.p.rutherford79@REMOVETHIS.gmail.com> - 2011-11-30 21:53 +0000
Re: Type interchange James Kuyper <jameskuyper@verizon.net> - 2011-11-30 17:29 -0500
Re: Type interchange Keith Thompson <kst-u@mib.org> - 2011-11-30 15:22 -0800
Re: Type interchange James Kuyper <jameskuyper@verizon.net> - 2011-11-30 19:10 -0500
Re: Type interchange Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-12-01 03:09 +0000
Re: Type interchange James Kuyper <jameskuyper@verizon.net> - 2011-12-01 07:13 -0500
Re: Type interchange Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-12-01 15:55 +0000
Re: Type interchange James Kuyper <jameskuyper@verizon.net> - 2011-12-01 11:28 -0500
Re: Type interchange Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-12-01 16:45 +0000
Re: Type interchange James Kuyper <jameskuyper@verizon.net> - 2011-12-01 12:00 -0500
Re: Type interchange Keith Thompson <kst-u@mib.org> - 2011-12-01 14:31 -0800
Re: Type interchange James Kuyper <jameskuyper@verizon.net> - 2011-12-01 20:18 -0500
Re: Type interchange Keith Thompson <kst-u@mib.org> - 2011-12-01 17:35 -0800
Re: Type interchange James Kuyper <jameskuyper@verizon.net> - 2011-12-02 12:03 -0500
Re: Type interchange Keith Thompson <kst-u@mib.org> - 2011-12-02 13:49 -0800
Re: Type interchange James Kuyper <jameskuyper@verizon.net> - 2011-12-02 22:12 -0500
Re: Type interchange Keith Thompson <kst-u@mib.org> - 2011-12-03 02:01 -0800
Re: Type interchange Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-25 12:47 -0800
Re: Type interchange pete <pfiland@mindspring.com> - 2011-12-01 11:10 -0500
Re: Type interchange James Kuyper <jameskuyper@verizon.net> - 2011-12-01 11:34 -0500
Re: Type interchange Kaz Kylheku <kaz@kylheku.com> - 2011-12-01 17:48 +0000
Re: Type interchange Keith Thompson <kst-u@mib.org> - 2011-12-01 14:17 -0800
Re: Type interchange pete <pfiland@mindspring.com> - 2011-12-01 17:43 -0500
Re: Type interchange Keith Thompson <kst-u@mib.org> - 2011-12-01 15:00 -0800
Re: Type interchange pete <pfiland@mindspring.com> - 2011-12-01 19:29 -0500
Re: Type interchange Keith Thompson <kst-u@mib.org> - 2011-12-01 16:59 -0800
Re: Type interchange pete <pfiland@mindspring.com> - 2011-12-02 08:35 -0500
Re: Type interchange James Kuyper <jameskuyper@verizon.net> - 2011-12-02 08:46 -0500
Re: Type interchange Keith Thompson <kst-u@mib.org> - 2011-12-02 13:32 -0800
Re: Type interchange Keith Thompson <kst-u@mib.org> - 2011-12-02 13:30 -0800
Re: Type interchange pete <pfiland@mindspring.com> - 2011-12-02 18:45 -0500
Re: Type interchange Keith Thompson <kst-u@mib.org> - 2011-11-30 19:17 -0800
Re: Type interchange James Kuyper <jameskuyper@verizon.net> - 2011-12-01 06:50 -0500
Re: Type interchange Keith Thompson <kst-u@mib.org> - 2011-12-01 07:15 -0800
Re: Type interchange James Kuyper <jameskuyper@verizon.net> - 2011-12-01 10:36 -0500
Re: Type interchange pete <pfiland@mindspring.com> - 2011-12-01 11:04 -0500
Re: Type interchange James Kuyper <jameskuyper@verizon.net> - 2011-12-01 11:37 -0500
Re: Type interchange Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-25 13:02 -0800
Re: Type interchange Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-25 13:01 -0800
Re: Type interchange Quentin Pope <qp19433@hotmail.NOSPAM.com> - 2011-12-02 22:15 +0000
Re: Type interchange James Kuyper <jameskuyper@verizon.net> - 2011-12-03 11:39 -0500
csiph-web