Thread View: comp.std.c++
2 messages
2 total messages
Started by Daniel Edelson
Tue, 18 Jun 1991 16:15
Re: Non-Portable pointer assignment?
Author: Daniel Edelson
Date: Tue, 18 Jun 1991 16:15
Date: Tue, 18 Jun 1991 16:15
38 lines
1665 bytes
1665 bytes
.Article: 2813 of comp.std.c
.From: hansen@pegasus.att.com (Tony L. Hansen)
.Subject: Re: Non-Portable pointer assignment?
.Date: 18 Jun 91 15:04:10 GMT
.
.< From: mcdaniel@adi.com (Tim McDaniel)
.< I would have been quite content to have seen the types and sizes of
.< 'xy' and 'x' differ.
.
.C++ has taken this tack: the type of 'x' is char while the type of 'xy' is
.int. It gives very nice properties when dealing with function and operator
.overloading.
.
. Tony Hansen
. hansen@pegasus.att.com, tony@attmail.com
. att!pegasus!hansen, attmail!tony
Thank you for pointing this out.
This means that the following program is legal in C++ and
ANSI C, and has different meanings in the two languages.
Am I correct in thinking that a design goal of Bjarne's was
to avoid the possibility of such a program?
Is that design goal sufficiently important to motivate x3j16
to change the type of 'c' to int?
#include <stdio.h>
int main(void)
{
printf("%d\n", sizeof('a'));
}
---
Daniel Edelson | ``Recycle your garbage. Please don't
daniel@cis.ucsc.edu, or | make me come and copy after you.''
uunet!ucscc!terra!daniel |
Re: Non-Portable pointer assignment?
Author: Joe Buck
Date: Tue, 18 Jun 1991 17:35
Date: Tue, 18 Jun 1991 17:35
35 lines
1795 bytes
1795 bytes
Tony Hansen writes:
|> .C++ has taken this tack: the type of 'x' is char while the type of 'xy' is
|> .int. It gives very nice properties when dealing with function and operator
|> .overloading.
In article <17163@darkstar.ucsc.edu>, daniel@cis.ucsc.edu (Daniel Edelson) writes:
|> Thank you for pointing this out.
|> This means that the following program is legal in C++ and
|> ANSI C, and has different meanings in the two languages.
|> Am I correct in thinking that a design goal of Bjarne's was
|> to avoid the possibility of such a program?
No, you aren't. There are a number of deliberate differences.
The win from being able to say
int foo;
cout << "The answer is " << foo << '\n';
far exceeds the rare cases where a different answer is obtained
in C and C++. You can still pass 'a' to a routine that expects
an int and have the right thing happen.
|> int main(void)
|> {
|> printf("%d\n", sizeof('a'));
|> }
But can you show me a real production program that produces
different answers? People very rarely write sizeof('a').
--
Joe Buck
jbuck@galileo.berkeley.edu {uunet,ucbvax}!galileo.berkeley.edu!jbuck
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads