static_cast versus C-style type cast

Discussion in 'C++' started by Dave Rahardja, Aug 18, 2003.

  1. 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
    Dave Rahardja, Aug 18, 2003
    #1
    1. Advertising

  2. Dave Rahardja

    Rolf Magnus Guest

    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.
    Rolf Magnus, Aug 18, 2003
    #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. Jim West
    Replies:
    4
    Views:
    1,407
    Jeff Schwab
    Jan 16, 2004
  2. Kobe
    Replies:
    3
    Views:
    545
    Tomás
    Feb 15, 2006
  3. Bo Peng
    Replies:
    11
    Views:
    1,072
    Victor Bazarov
    Oct 20, 2006
  4. Paul Butcher
    Replies:
    12
    Views:
    694
    Gary Wright
    Nov 28, 2007
  5. junyangzou
    Replies:
    13
    Views:
    248
Loading...

Share This Page