Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > deprecating T(V) as c-style cast for POD T in favor of initializationsemantics - Off topic kinda

Reply
Thread Tools

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

 
 
Gianni Mariani
Guest
Posts: n/a
 
      10-28-2008
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.
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      10-28-2008
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Apple is deprecating Java Xah Lee Java 80 11-18-2010 11:11 PM
OFF TOPIC:Re: C compiler question (I hope this is on topic) jacob navia C Programming 5 05-30-2010 02:22 PM
deprecating abstract methods Thomas Hawtin Java 5 04-17-2006 01:54 PM
Is array of POD still a POD type? Ajax Chelsea C++ 1 12-01-2003 01:56 PM
A (probable) error in perltoot ( perl5/5.8.0/pod/perltoot.pod, line number 756 ) Himanshu Garg Perl Misc 1 09-21-2003 03:28 AM



Advertisments