Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > static_cast versus C-style type cast

Reply
Thread Tools

static_cast versus C-style type cast

 
 
Dave Rahardja
Guest
Posts: n/a
 
      08-18-2003
Is there a difference between a static_cast and an C-style type cast?

In other words, is there a difference between...

int a;
unsigned b = static_cast<unsigned>(a); // static_cast
unsigned c = (unsigned)(a); // C-style cast

 
Reply With Quote
 
 
 
 
Rolf Magnus
Guest
Posts: n/a
 
      08-18-2003
Dave Rahardja wrote:

> Is there a difference between a static_cast and an C-style type cast?


Yes.

> In other words, is there a difference between...
>
> int a;
> unsigned b = static_cast<unsigned>(a); // static_cast
> unsigned c = (unsigned)(a); // C-style cast


No.
A static_cast is more restrictive than a C style cast. The latter will
do the same as any combination of static_cast, const_cast and
reinterpret_cast that is necessary for the requested convertion.

 
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
Re: Mozilla versus IE versus Opera versus Safari Peter Potamus the Purple Hippo Firefox 0 05-08-2008 12:56 PM
equal? versus eql? versus == versus === verus <=> Paul Butcher Ruby 12 11-28-2007 06:06 AM
Is static_cast<int>(static_cast<double>(a)) == a? Bo Peng C++ 11 10-20-2006 12:59 PM
Moving to static_cast and reinterpret_cast from old C-style cast Kobe C++ 3 02-15-2006 08:13 PM
static_cast vs. C-stype cast Alexander Stippler C++ 2 12-10-2003 11:24 AM



Advertisments