Topic: Non-Portable pointer assignment?
Author: jbuck@forney.berkeley.edu (Joe Buck)
Date: 18 Jun 91 17:35:59 GMT Raw View
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
Author: jimad@microsoft.UUCP (Jim ADCOCK)
Date: 27 Jun 91 21:51:42 GMT Raw View
In article <17163@darkstar.ucsc.edu> daniel@cis.ucsc.edu (Daniel Edelson) writes:
|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?
Obviously not, since he clearly anticipated the possibility of such
a program when he changed the type of 'c' from int to char a few
years ago. I think those of us programming in C++ at the time
found the change a major win.
I would hope that if the changes from "C" to "C++" are small compared
to the changes from "C" to "ANSI-C" [value preserving compared to
unsigned preserving, and major changes to the preprocessor, for example],
and if those changes are also small compared to the variability of compilers
from various vendors, and if those changes can be detected by compilers
and warning issued, -- well, then I would hope "C++" can be allowed to make
some tiny changes from historical "C" in order to make C++ a more
consistent and useful language.
|Is that design goal sufficiently important to motivate x3j16
|to change the type of 'c' to int?
Well, I don't believe your statement of a particular design goal
is a correct statement of "the" overriding "C++" design goal,
and I believe the change from int to char was perceived as a major
win in the C++ community, so I would hope x3j16 is not so motivated.
Author: daniel@cis.ucsc.edu (Daniel Edelson)
Date: 18 Jun 91 16:15:56 GMT Raw View
.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 |