deprecating T(V) as c-style cast for POD T in favor of initializationsemantics - Off topic kinda

Discussion in 'C++' started by Gianni Mariani, Oct 28, 2008.

  1. So I was put straight that double(v) is the same as (double)(v)
    recently and I'm somewhat surprised. I'm not the only one.

    I think T(V) should have exactly the same semantics as
    static_cast<T>(V) for POD T and I'm willing to bet you'll find few C++
    developers that would object.

    What I'd like to propose is that the c-style cast interpretation of
    T(V) for POD T be the same as initialization of a temporary object T
    with a value V. i.e. T id(V).

    The rationale is that T(V) being a C-ctyle cast is far more dangerous
    than using a c-style cast because use of T(V) in templates is often
    used to initialize a temporary T and the fact that it becomes a c-
    style cast in some cases and is an initialization in others would be
    mostly unintended.

    I do believe that most current uses of the T(V) syntax for POD T would
    be in cases were the developer intended a static cast or
    initialization so there would be very few cases where this would be
    problematic. Deprecating the c-ctyle cast meaning should have minimal
    undesired impact.

    I'd like to hear how others feel about this.
     
    Gianni Mariani, Oct 28, 2008
    #1
    1. Advertising

  2. Gianni Mariani

    Ian Collins Guest

    Gianni Mariani wrote:
    > So I was put straight that double(v) is the same as (double)(v)
    > recently and I'm somewhat surprised. I'm not the only one.
    >
    > I think T(V) should have exactly the same semantics as
    > static_cast<T>(V) for POD T and I'm willing to bet you'll find few C++
    > developers that would object.
    >
    > What I'd like to propose is that the c-style cast interpretation of
    > T(V) for POD T be the same as initialization of a temporary object T
    > with a value V. i.e. T id(V).
    >
    > The rationale is that T(V) being a C-ctyle cast is far more dangerous
    > than using a c-style cast because use of T(V) in templates is often
    > used to initialize a temporary T and the fact that it becomes a c-
    > style cast in some cases and is an initialization in others would be
    > mostly unintended.
    >

    Well it certainly isn't a C style cast for pointers. You can't write

    void* p;

    int* n(p);

    --
    Ian Collins
     
    Ian Collins, Oct 28, 2008
    #2
    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. Thomas Hawtin

    deprecating abstract methods

    Thomas Hawtin, Apr 10, 2006, in forum: Java
    Replies:
    5
    Views:
    650
    Gabriel Belingueres
    Apr 17, 2006
  2. Wayne...
    Replies:
    15
    Views:
    791
    Toby Inkster
    Jul 23, 2004
  3. Ajax Chelsea

    Is array of POD still a POD type?

    Ajax Chelsea, Dec 1, 2003, in forum: C++
    Replies:
    1
    Views:
    367
    Ron Natalie
    Dec 1, 2003
  4. jacob navia
    Replies:
    5
    Views:
    567
    spinoza1111
    May 30, 2010
  5. Himanshu Garg
    Replies:
    1
    Views:
    181
    Himanshu Garg
    Sep 21, 2003
Loading...

Share This Page