Strange Article on C++ casts

Discussion in 'C++' started by charlie, Jan 11, 2007.

  1. charlie

    charlie Guest

    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
     
    charlie, Jan 11, 2007
    #1
    1. Advertising

  2. charlie wrote:

    > 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"

    --
    Salu2
     
    =?ISO-8859-15?Q?Juli=E1n?= Albo, Jan 11, 2007
    #2
    1. Advertising

  3. charlie

    charlie Guest

    On Jan 11, 11:56 am, Julián Albo <> wrote:
    > charlie wrote:
    > > 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"
    >
    > --
    > Salu2


    <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.
     
    charlie, Jan 11, 2007
    #3
  4. charlie wrote:
    > 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
     
    Stuart Redmann, Jan 11, 2007
    #4
  5. charlie

    Ian Collins Guest

    charlie wrote:
    > 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?

    --
    Ian Collins.
     
    Ian Collins, Jan 11, 2007
    #5
  6. charlie

    charlie Guest

    On Jan 11, 12:51 pm, Ian Collins <> wrote:
    > charlie wrote:
    > > 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?

    >
    > --
    > Ian Collins.


    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
     
    charlie, Jan 11, 2007
    #6
  7. charlie

    peter koch Guest

    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
     
    peter koch, Jan 11, 2007
    #7
  8. charlie

    Pete Becker Guest

    peter koch wrote:
    > I believe that
    > getting on the C++ standards committee is possible even if you are a
    > far way from being an expert.
    >


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

    --

    -- Pete
    Roundhouse Consulting, Ltd. (www.versatilecoding.com)
    Author of "The Standard C++ Library Extensions: a Tutorial and
    Reference." (www.petebecker.com/tr1book)
     
    Pete Becker, Jan 11, 2007
    #8
  9. charlie

    peter koch Guest

    Pete Becker skrev:
    > peter koch wrote:
    > > I believe that
    > > getting on the C++ standards committee is possible even if you are a
    > > far way from being an expert.
    > >

    >
    > 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
     
    peter koch, Jan 11, 2007
    #9
  10. charlie

    Pete Becker Guest

    peter koch wrote:
    > Pete Becker skrev:
    >> peter koch wrote:
    >>> I believe that
    >>> getting on the C++ standards committee is possible even if you are a
    >>> far way from being an expert.
    >>>

    >> 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?
    >


    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)
     
    Pete Becker, Jan 11, 2007
    #10

  11. > 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... ;)
     
    Gernot Frisch, Jan 11, 2007
    #11
  12. charlie

    peter koch Guest

    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
     
    peter koch, Jan 11, 2007
    #12
  13. charlie wrote:

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

    >> 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.


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

    --
    Salu2
     
    =?ISO-8859-15?Q?Juli=E1n?= Albo, Jan 11, 2007
    #13
  14. charlie

    Grizlyk Guest

    peter koch ÐÉÓÁÌ(Á):

    > The review can be found at
    > http://accu.org/index.php/book_reviews?url=view.xqy?review=a002154&term=ansi


    "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?
     
    Grizlyk, Jan 14, 2007
    #14
  15. charlie

    peter koch Guest

    Grizlyk skrev:
    > peter koch ÐÉÓÁÌ(Á):
    >
    > > The review can be found at
    > > http://accu.org/index.php/book_reviews?url=view.xqy?review=a002154&term=ansi

    >
    > "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
     
    peter koch, Jan 14, 2007
    #15
  16. charlie

    Grizlyk Guest

    peter koch wrote:
    > >
    > > 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& );


    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() ); }
     
    Grizlyk, Jan 14, 2007
    #16
  17. charlie

    peter koch Guest

    Grizlyk skrev:
    > peter koch wrote:
    > > >
    > > > 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& );

    >
    > 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.
    >
    > > private:
    > > myclass(myclass const& ) {}

    >
    > 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
     
    peter koch, Jan 14, 2007
    #17
  18. charlie

    Grizlyk Guest

    peter koch wrote:
    > >
    > >Grizlyk skrev:
    > >
    > > myclass(myclass const& )throw(Myerror&)
    > > { throw Terr_private( typeid(*this).name() ); }

    >
    > 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.
     
    Grizlyk, Jan 15, 2007
    #18
  19. charlie

    peter koch Guest

    Grizlyk skrev:
    > peter koch wrote:
    > > >
    > > >Grizlyk skrev:
    > > >
    > > > myclass(myclass const& )throw(Myerror&)
    > > > { throw Terr_private( typeid(*this).name() ); }

    > >
    > > 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 :)

    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
     
    peter koch, Jan 15, 2007
    #19
  20. charlie

    Grizlyk Guest

    peter koch wrote:

    > > > >Grizlyk skrev:
    > > > >
    > > > > myclass(myclass const& )throw(Myerror&)
    > > > > { throw Terr_private( typeid(*this).name() ); }
    > > >
    > > > 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 :)

    >
    > 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.

    > > 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.


    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.
     
    Grizlyk, Jan 16, 2007
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Q2hyaXMgRGF2b2xp?=

    Web casts in ASP.Net

    =?Utf-8?B?Q2hyaXMgRGF2b2xp?=, Oct 19, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    528
    clintonG
    Oct 19, 2005
  2. cgbusch
    Replies:
    2
    Views:
    349
    Sudsy
    Jul 8, 2003
  3. Joona I Palaste

    Needless casts?

    Joona I Palaste, Apr 24, 2004, in forum: Java
    Replies:
    15
    Views:
    715
    Icemerth
    Apr 25, 2004
  4. Dan Upton

    checking casts

    Dan Upton, Nov 29, 2005, in forum: Java
    Replies:
    4
    Views:
    762
    Chris Smith
    Dec 1, 2005
  5. Wenjie

    C++ casts on zero

    Wenjie, Aug 17, 2003, in forum: C++
    Replies:
    11
    Views:
    690
    Wenjie
    Aug 24, 2003
Loading...

Share This Page