Strange Article on C++ casts

C

charlie

Hi,

I found an article on informit.com that talks about C++ casts

http://www.informit.com/guides/content.asp?g=cplusplus&seqNum=285&rl=1

The strange thing is the author says the following code will *not*
compile:
double d=15.95;
int n= static_cast<int> (d);

and then he goes on to launch an attack against C++ casts. I can't see
any reason why it shouldn't work and I tried with the MS and INTEL
compilers and it compiles with nary a problem.

Does anyone know what he's trying to say???

cheers,
/Charles
 
?

=?ISO-8859-15?Q?Juli=E1n?= Albo

charlie said:
The strange thing is the author says the following code will *not*
compile:
double d=15.95;
int n= static_cast<int> (d);
and then he goes on to launch an attack against C++ casts. I can't see
any reason why it shouldn't work and I tried with the MS and INTEL
compilers and it compiles with nary a problem.
Does anyone know what he's trying to say???

I'm almost sure that the author tries to say: "C++ sucks, my favorite
language is better"
 
C

charlie

language is better"

<grin> Well I would agree with you normally but he's a C++ guy. He's
even served on the C++ standards committee. So it seems to be a strange
mistake to make.
 
S

Stuart Redmann

charlie said:
Hi,

I found an article on informit.com that talks about C++ casts

http://www.informit.com/guides/content.asp?g=cplusplus&seqNum=285&rl=1

The strange thing is the author says the following code will *not*
compile:
double d=15.95;
int n= static_cast<int> (d);

The code I actually found there was:

int n;
double d=15.95;
int n= static_cast<int> (d);

which won't compile as the variable n is defined twice. Having removed
the first definition of n, the code compiles fine and does what it should.
and then he goes on to launch an attack against C++ casts.

Obviously he doesn't know anything about them and won't bother to look
into his textbook.
I can't see
any reason why it shouldn't work and I tried with the MS and INTEL
compilers and it compiles with nary a problem.

Does anyone know what he's trying to say???

Nope. Ignore him.

Regards,
Stuart
 
I

Ian Collins

charlie said:
Hi,

I found an article on informit.com that talks about C++ casts

http://www.informit.com/guides/content.asp?g=cplusplus&seqNum=285&rl=1

The strange thing is the author says the following code will *not*
compile:
double d=15.95;
int n= static_cast<int> (d);

and then he goes on to launch an attack against C++ casts. I can't see
any reason why it shouldn't work and I tried with the MS and INTEL
compilers and it compiles with nary a problem.

Does anyone know what he's trying to say???
That he doesn't know what he is talking about?
 
C

charlie

Ok great. I just got confused cause he's a published guy who worked on
the the C++ standards committee. But I guess that don't necessarily
mean much :)

/Charles
 
P

peter koch

charlie skrev:
Hi,

I found an article on informit.com that talks about C++ casts

http://www.informit.com/guides/content.asp?g=cplusplus&seqNum=285&rl=1

The strange thing is the author says the following code will *not*
compile:
double d=15.95;
int n= static_cast<int> (d);

This snippet is perfectly ok, of course.
and then he goes on to launch an attack against C++ casts. I can't see
any reason why it shouldn't work and I tried with the MS and INTEL
compilers and it compiles with nary a problem.

Does anyone know what he's trying to say???
I've read some of the stuff he wrote at informit, and there are several
areas where stuff looked dubious (to be nice). To be nice to Danny
Kalev, there are also some articles that are okay. I believe that
getting on the C++ standards committee is possible even if you are a
far way from being an expert.

/Peter
 
P

peter koch

Pete Becker skrev:
All you have to do is pay INCITS for the privelege. There are many
silent members.

I expected something in that direction. How much money are we talking
about?

/Peter
 
P

Pete Becker

peter said:
Pete Becker skrev:

I expected something in that direction. How much money are we talking
about?

Currently, $800 per year. And I should have mentioned that INCITS is the
US organization. Other countries organize things differently.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
 
G

Gernot Frisch

Ok great. I just got confused cause he's a published guy who worked
on
the the C++ standards committee. But I guess that don't necessarily
mean much :)


We're all gonna die! Bwahaaaaa... ;)
 
P

peter koch

charlie skrev:
[snip]
<grin> Well I would agree with you normally but he's a C++ guy. He's
even served on the C++ standards committee. So it seems to be a strange
mistake to make.

I've been digging some more and found that he is an author of "The
ANSI/ISO C++ Professional Programmer's Handbook" which at accu.org was
reviewed as "Not recommended". Francis Glassborow begins his review
with:
"I wish the publishers had not stated that the author is a member of
the ISO/ANSI C++ Standards Committees as it lends more authority to his
work than it deserves. To the best of my knowledge the author has never
attended a meeting of WG21 & J16. That is not to say that there is no
justification for the statement. Kalev is listed as an observer and is
entitled to participate in any of the C++ Standards reflectors that he
wishes to, however his is not a name that springs to mind as an active
participant (I do take almost all the C++ Standards reflectors and
think I am reasonably familiar with the active participants)."
The review can be found at
http://accu.org/index.php/book_reviews?url=view.xqy?review=a002154&term=ansi

/Peter
 
?

=?ISO-8859-15?Q?Juli=E1n?= Albo

charlie said:
<grin> Well I would agree with you normally but he's a C++ guy. He's
even served on the C++ standards committee. So it seems to be a strange
mistake to make.

My mistake, I blindly assumed it was some type of joke and don't clicked the
url, sorry.
 
G

Grizlyk

peter koch ÐÉÓÁÌ(Á):

"he shows that he does not understand the full method because he
provides inline definitions (not just declarations) for the _private_
access copy constructor and assignment operator"

What's ugly wrong with definitions of copy constructor and assignment
operator? They can be called in some cases by the object itself and
what the dangerous?
 
P

peter koch

Grizlyk skrev:
peter koch ÐÉÓÁÌ(Á):


"he shows that he does not understand the full method because he
provides inline definitions (not just declarations) for the _private_
access copy constructor and assignment operator"

What's ugly wrong with definitions of copy constructor and assignment
operator? They can be called in some cases by the object itself and
what the dangerous?
If you want to disable e.g. copy constructing, this is defined by
having the constructor private and without an implementation:
private:
myclass(myclass const& );

and not as was apparantly done give it a body:
private:
myclass(myclass const& ) {}

/Peter
 
G

Grizlyk

peter said:
If you want to disable e.g. copy constructing, this is defined by
having the constructor private and without an implementation:
private:
myclass(myclass const& );

Are you shure, the compiler will not request (as error or warning) to
define "myclass(myclass const& )"? It is good stuff, but as i can
rememver, in old compilers were troubles with it (errors or warnings),
i am not shure.
private:
myclass(myclass const& ) {}

No, not of course, do like this:
private:
myclass(myclass const& )throw(Myerror&) { throw Terr_private(
typeid(*this).name() ); }
 
P

peter koch

Grizlyk skrev:
Are you shure, the compiler will not request (as error or warning) to
define "myclass(myclass const& )"? It is good stuff, but as i can
rememver, in old compilers were troubles with it (errors or warnings),
i am not shure.
Yes I am sure. What old compilers did or did not is irrelevant here.
No, not of course, do like this:
private:
myclass(myclass const& )throw(Myerror&) { throw Terr_private(
typeid(*this).name() ); }
That can never be correct. If anything, an abort is in place.

/Peter
 
G

Grizlyk

peter said:
That can never be correct. If anything, an abort is in place.
What does it ("If anything, an abort is in place") mean? Sorry, I can
not translate it and understand.
If no explanaition exist, I silently will ignore the opinion, for it
contradicts my observations :)

Look
1. I am not "Danny Kalev".
2. I am not going to buy his book now or in future.

But the notes of "Francis Glassborow" here
http://accu.org/index.php/book_reviews?url=view.xqy?review=a002154&term=ansi

looks like personal attack. "he is just not with Us" - sad "Francis
Glassborow" with long explanations. In general it is not enough to be
wrong.

I think, that book about details of C++ must be written by C++ expert.
In order to show, that "Danny Kalev" is not, "Francis Glassborow" can
just project the list of many undiscussable hard errors in the book
instead of "he was invisible on our meetings".

There are tons of thrash, named as "became C++ expert for one our" or
"take our beer, wait just twenty years and you are C++ expert now". It
is possible, some of them were written by people from "C++ Standards
Committees" :)

If the "comettee" does not agreed with the ideas of the book in general
or in concretes cases,
the comettee even can gather and make issue of the note, if "comettee"
may do it and it is important.

If the "Francis Glassborow" care only of honor of the comettee as
private man, he just can say, that ideas of
any private member of "comettee" can not be treated even as unofficial
opinion of the "comettee",
and always better give list of errors.
 
P

peter koch

Grizlyk skrev:
What does it ("If anything, an abort is in place") mean? Sorry, I can
not translate it and understand.
If no explanaition exist, I silently will ignore the opinion, for it
contradicts my observations :)
It simply means that if a class is not copy-constructible, you should
not write a copy constructor. Writing a copy constructor that throws is
simply wrong: C++ exceptions are not for programming errors.
My (silly) suggestion to call abort was meant to be used in the
unlikely event someone should stumble over a compiler where you were
forced to implement the copy-constructor. But I've never seen or heard
about such a compiler, and considering the trickery involved in
implementing such a beast and the problem to find any real codebase
that would compile, I must say I find that most unlikely to ever
happen.
Look
1. I am not "Danny Kalev".
2. I am not going to buy his book now or in future.

But the notes of "Francis Glassborow" here
http://accu.org/index.php/book_reviews?url=view.xqy?review=a002154&term=ansi

looks like personal attack. "he is just not with Us" - sad "Francis
Glassborow" with long explanations. In general it is not enough to be
wrong.

I think, that book about details of C++ must be written by C++ expert.
In order to show, that "Danny Kalev" is not, "Francis Glassborow" can
just project the list of many undiscussable hard errors in the book
instead of "he was invisible on our meetings".

Glassborow did just that. There were three examples of C++ ignorance in
a one page long review.
There are tons of thrash, named as "became C++ expert for one our" or
"take our beer, wait just twenty years and you are C++ expert now". It
is possible, some of them were written by people from "C++ Standards
Committees" :)

Actually, Danny Kalev was such a member: as noted elsewhere in this
thread it only requires paying a modest fee to your national standard
organisation, at least in the US. While other members might also write
bad books, chances are that they will not make such obvious errors as
generously provided by Kalev.
If the "comettee" does not agreed with the ideas of the book in general
or in concretes cases,
the comettee even can gather and make issue of the note, if "comettee"
may do it and it is important.

If the "Francis Glassborow" care only of honor of the comettee as
private man, he just can say, that ideas of
any private member of "comettee" can not be treated even as unofficial
opinion of the "comettee",
and always better give list of errors.
This is not a matter of taste or agreement. The book is simply
objectively wrong and thats it.

/Peter
 
G

Grizlyk

peter said:
It simply means that if a class is not copy-constructible, you should
not write a copy constructor. Writing a copy constructor that throws is
simply wrong: C++ exceptions are not for programming errors.

I can not prove my opinion, that "some old compilers required all
constructors defined if they are declared", but I can say, that the
evil tidings "to define private member as throw error" among me is
existing for my classes at least for 10 years (from 2000 year). Yes, I
do not use C++ intensively for all the years (there was many years,
when i never see not a line of C++ code), but after the time I forgot
the cause to do like this, just copying it :)

It is possible, "private member as throw error" is ancient error, but
agree, so longlife invisible "error" easy prove, that "error" is not
error. Really, it is does not metter for practiacal use, "to define
private member as throw error" or "to not define private member" (i see
differences), but yes, last is more smart solution and in general
better. I feel a reason to change my tradition :)

The worst way is "defining private member as empty code" or "defining
private member as calling exit() or abort()": both is ugly wrong.
Glassborow did just that. There were three examples of C++ ignorance in
a one page long review.

I saw the examples, but all of them can be easy treated as "does not
matter" and Glassborow objections _looks_ just like "game with words".
I agree, that man (Danny Kalev) who describe standard must be more
pedantic than pedanctic, but can repeat again - Glassborow was not
convincing, he just not listed very ugly obvious errors.

All Glassborow examples less than 5% of size of his note, other about
him and comitee. Most engeneers ignore results, if value is less than
10% of other value :) All Glassborow examples is strange shortest parts
of unknown code, without any sence and original context.
This is not a matter of taste or agreement. The book is simply
objectively wrong and thats it.

It is possible, i do not see the book. And i am not going to do it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top