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. type casting

type casting

Scheduled Pinned Locked Moved C / C++ / MFC
performancequestion
6 Posts 6 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.
  • N Offline
    N Offline
    NicholasCougar
    wrote on last edited by
    #1

    Hi, Look at the code below

    #define MAKEINTRESOURCE(i) (LPTSTR) ((DWORD) ((WORD) (i)))

    If it's a type casting, I feel it's terrible. My question is: Inside memory, what the variable i look like after this terrible type casting Any information concerned is appreciated. Thank you Best regard. I confess that I am a stubborn guy, but why not put things thoroughly, logically and systematically clean. One concrete prolem is worth a thousand unapplied abstractions.

    N N P A 4 Replies Last reply
    0
    • N NicholasCougar

      Hi, Look at the code below

      #define MAKEINTRESOURCE(i) (LPTSTR) ((DWORD) ((WORD) (i)))

      If it's a type casting, I feel it's terrible. My question is: Inside memory, what the variable i look like after this terrible type casting Any information concerned is appreciated. Thank you Best regard. I confess that I am a stubborn guy, but why not put things thoroughly, logically and systematically clean. One concrete prolem is worth a thousand unapplied abstractions.

      N Offline
      N Offline
      Niklas L
      wrote on last edited by
      #2

      The high word of 'i' will be cleared, since the WORD type cast will remove it. The DWORD type adds a high word of zero's. The LPTSTR does just change the type of the DWORD to a character pointer, with no effects on the bits in memory.

      J 1 Reply Last reply
      0
      • N NicholasCougar

        Hi, Look at the code below

        #define MAKEINTRESOURCE(i) (LPTSTR) ((DWORD) ((WORD) (i)))

        If it's a type casting, I feel it's terrible. My question is: Inside memory, what the variable i look like after this terrible type casting Any information concerned is appreciated. Thank you Best regard. I confess that I am a stubborn guy, but why not put things thoroughly, logically and systematically clean. One concrete prolem is worth a thousand unapplied abstractions.

        N Offline
        N Offline
        Nish Nishant
        wrote on last edited by
        #3

        If you dont try to modify the pointer returned from MAKEINTRESOURCE, things are okay. Anyhow MSDN has this warning :- "The return value from MAKEINTRESOURCE should be passed only to the Win32 resource-management functions" Nish


        Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

        1 Reply Last reply
        0
        • N Niklas L

          The high word of 'i' will be cleared, since the WORD type cast will remove it. The DWORD type adds a high word of zero's. The LPTSTR does just change the type of the DWORD to a character pointer, with no effects on the bits in memory.

          J Offline
          J Offline
          Jon Hulatt
          wrote on last edited by
          #4

          Where's Christian?? He won't like that c-style cast one little bit :) Signature space for rent. Apply Within.

          1 Reply Last reply
          0
          • N NicholasCougar

            Hi, Look at the code below

            #define MAKEINTRESOURCE(i) (LPTSTR) ((DWORD) ((WORD) (i)))

            If it's a type casting, I feel it's terrible. My question is: Inside memory, what the variable i look like after this terrible type casting Any information concerned is appreciated. Thank you Best regard. I confess that I am a stubborn guy, but why not put things thoroughly, logically and systematically clean. One concrete prolem is worth a thousand unapplied abstractions.

            P Offline
            P Offline
            Paul M Watt
            wrote on last edited by
            #5

            Yes, this is type casting. Because the compiler verifies that all computations in your program use compatible datatypes, type casting becomes necessary when you have two data types in a calculation that are not compatible by default. The MAKEINTRESOURCE macro is a very useful macro, that does serve a good purpose, and is not considered terrible. It allows you to refer to a resource in your module by either a NULL terminated string, or a resource ID. This type of cast, where you place the target data type in ( ), is called a C-style cast. This is equivalent to the reinterpret_cast operator in C++. It tells the compiler to disregard the format of the data that you are type casting from, and think of it as another, possibly incompatible format. So this type-cast operation does not change anything inside of memory, it just makes the compiler think of your type-cast variable as another format so that it will not complain that you are trying to form a calculation with two incompatible types.


            Build a man a fire, and he will be warm for a day
            Light a man on fire, and he will be warm for the rest of his life!

            1 Reply Last reply
            0
            • N NicholasCougar

              Hi, Look at the code below

              #define MAKEINTRESOURCE(i) (LPTSTR) ((DWORD) ((WORD) (i)))

              If it's a type casting, I feel it's terrible. My question is: Inside memory, what the variable i look like after this terrible type casting Any information concerned is appreciated. Thank you Best regard. I confess that I am a stubborn guy, but why not put things thoroughly, logically and systematically clean. One concrete prolem is worth a thousand unapplied abstractions.

              A Offline
              A Offline
              Aizik Yair
              wrote on last edited by
              #6

              answer: Pointer to a null-terminated string of 16-bit Unicode characters. Aizik Yair Software Engineer

              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