Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. static_cast

static_cast

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    ov
    wrote on last edited by
    #1

    Does static_cast<> produce any code or

    class_A_ptr *a = static_cast < class_B_ptr * > (b);

    is equal to

    class_A_ptr *a = (class_B_ptr *)b;

    ? With the best regards, Vitaly.

    L E 2 Replies Last reply
    0
    • O ov

      Does static_cast<> produce any code or

      class_A_ptr *a = static_cast < class_B_ptr * > (b);

      is equal to

      class_A_ptr *a = (class_B_ptr *)b;

      ? With the best regards, Vitaly.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Testing with MS Visual C++, in release build, no difference, code size was the same either way.

      1 Reply Last reply
      0
      • O ov

        Does static_cast<> produce any code or

        class_A_ptr *a = static_cast < class_B_ptr * > (b);

        is equal to

        class_A_ptr *a = (class_B_ptr *)b;

        ? With the best regards, Vitaly.

        E Offline
        E Offline
        Erik Funkenbusch
        wrote on last edited by
        #3

        the newstyle casts are basically the same as the oldstyle casts, except the results are more clearly defined. (class_B_ptr*) is actually a combination of several kinds of casts, const_cast and static_cast depending on situation. there is also dynamic_cast and reinterpret_cast, which all do different things, and only very specific things (unlike the oldstyle casts which would often allow you to do something you didn't intend to do). static_cast can sometimes generate code, for instance, when casting an object with multiple vtables, the vtable is adjusted when you cast it. but generally speaking it usually does not.

        O 1 Reply Last reply
        0
        • E Erik Funkenbusch

          the newstyle casts are basically the same as the oldstyle casts, except the results are more clearly defined. (class_B_ptr*) is actually a combination of several kinds of casts, const_cast and static_cast depending on situation. there is also dynamic_cast and reinterpret_cast, which all do different things, and only very specific things (unlike the oldstyle casts which would often allow you to do something you didn't intend to do). static_cast can sometimes generate code, for instance, when casting an object with multiple vtables, the vtable is adjusted when you cast it. but generally speaking it usually does not.

          O Offline
          O Offline
          ov
          wrote on last edited by
          #4

          thanks a lot :) With the best regards, Vitaly.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups