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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. DWORD dw='pp' is valid in VC++ 6.0 :(

DWORD dw='pp' is valid in VC++ 6.0 :(

Scheduled Pinned Locked Moved C / C++ / MFC
c++
11 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.
  • R Offline
    R Offline
    Raj Prathap
    wrote on last edited by
    #1

    I'm using VS6.0. I was going through the code which was written nearly 3 years before. I have seen one statement like said in the subject DWORD dw='pp'; I was not aware that is a valid statement. And still I'm not clear what will be the value of dw. I calculated if it is equivalent to ('p'<<8 + 'p') but no success. Can some kindly clarify me on whether two characters in single cotes is valid in C/C++ or it is valid only in VC++. If valid in VC++, how would the value is calculated for the literal in two cotes. regards, Pratap

    T N D D 4 Replies Last reply
    0
    • R Raj Prathap

      I'm using VS6.0. I was going through the code which was written nearly 3 years before. I have seen one statement like said in the subject DWORD dw='pp'; I was not aware that is a valid statement. And still I'm not clear what will be the value of dw. I calculated if it is equivalent to ('p'<<8 + 'p') but no success. Can some kindly clarify me on whether two characters in single cotes is valid in C/C++ or it is valid only in VC++. If valid in VC++, how would the value is calculated for the literal in two cotes. regards, Pratap

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      'pp' is not a valid character, but AFAIK, it is understood as if it were the first character written solely : 'p' so, you DWORD contains the ascii code of 'p', chis is 112 (0x00000070)


      [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

      R CPalliniC 2 Replies Last reply
      0
      • T toxcct

        'pp' is not a valid character, but AFAIK, it is understood as if it were the first character written solely : 'p' so, you DWORD contains the ascii code of 'p', chis is 112 (0x00000070)


        [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

        R Offline
        R Offline
        Raj Prathap
        wrote on last edited by
        #3

        No! The DWORD value is coming as 28784 in my machine

        T 1 Reply Last reply
        0
        • R Raj Prathap

          No! The DWORD value is coming as 28784 in my machine

          T Offline
          T Offline
          toxcct
          wrote on last edited by
          #4

          so, that is 0x7070... strange, but quite logical if we know that 'p' is 0x70


          [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

          R 1 Reply Last reply
          0
          • T toxcct

            so, that is 0x7070... strange, but quite logical if we know that 'p' is 0x70


            [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

            R Offline
            R Offline
            Raj Prathap
            wrote on last edited by
            #5

            I'm sorry There was a mistake in calculating the value of 0x7070 in decimal format. The value is 0x7070 only!! Thanks a lot for your support!! could you kindly specify that the statement DWORD dw='pp'; is valid in all platforms!! I'm googling for it, but no success!!

            1 Reply Last reply
            0
            • R Raj Prathap

              I'm using VS6.0. I was going through the code which was written nearly 3 years before. I have seen one statement like said in the subject DWORD dw='pp'; I was not aware that is a valid statement. And still I'm not clear what will be the value of dw. I calculated if it is equivalent to ('p'<<8 + 'p') but no success. Can some kindly clarify me on whether two characters in single cotes is valid in C/C++ or it is valid only in VC++. If valid in VC++, how would the value is calculated for the literal in two cotes. regards, Pratap

              N Offline
              N Offline
              Nishad S
              wrote on last edited by
              #6

              Raj Prathap wrote:

              was not aware that is a valid statement.

              It is a valid statement.

              Raj Prathap wrote:

              And still I'm not clear what will be the value of dw.

              DWORD is four bytes long. The higher two bytes will be 0 and the lower two bytes will be the value 'p'. Like 0x00007070. And if it was 'pa' then value would be 0x00007061. Also upto 4 characters are possible. For example dw = 'abcd' means 0x61626364.

              Raj Prathap wrote:

              I calculated if it is equivalent to ('p'<<8 + 'p') but no success.

              The problem caused with your code is the precedence of operators. Try DWORD dw = ( 'p' << 8 ) + 'a';

              - NS -

              1 Reply Last reply
              0
              • T toxcct

                'pp' is not a valid character, but AFAIK, it is understood as if it were the first character written solely : 'p' so, you DWORD contains the ascii code of 'p', chis is 112 (0x00000070)


                [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                CPalliniC Offline
                CPalliniC Offline
                CPallini
                wrote on last edited by
                #7

                toxcct wrote:

                'pp' is not a valid character,

                it is a valid (though discouraged) multicharacter constant, see [^].

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

                In testa che avete, signor di Ceprano?

                R 1 Reply Last reply
                0
                • R Raj Prathap

                  I'm using VS6.0. I was going through the code which was written nearly 3 years before. I have seen one statement like said in the subject DWORD dw='pp'; I was not aware that is a valid statement. And still I'm not clear what will be the value of dw. I calculated if it is equivalent to ('p'<<8 + 'p') but no success. Can some kindly clarify me on whether two characters in single cotes is valid in C/C++ or it is valid only in VC++. If valid in VC++, how would the value is calculated for the literal in two cotes. regards, Pratap

                  D Offline
                  D Offline
                  Don Box
                  wrote on last edited by
                  #8

                  Hi! If you wanna know the Correct answer, then first respond to this.

                  Come online at:- jubinc@skype

                  1 Reply Last reply
                  0
                  • R Raj Prathap

                    I'm using VS6.0. I was going through the code which was written nearly 3 years before. I have seen one statement like said in the subject DWORD dw='pp'; I was not aware that is a valid statement. And still I'm not clear what will be the value of dw. I calculated if it is equivalent to ('p'<<8 + 'p') but no success. Can some kindly clarify me on whether two characters in single cotes is valid in C/C++ or it is valid only in VC++. If valid in VC++, how would the value is calculated for the literal in two cotes. regards, Pratap

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #9

                    Raj Prathap wrote:

                    DWORD dw='pp'; I was not aware that is a valid statement.

                    It is, because 'pp' is treated as an int, and since it is being assigned to a DWORD, all is well. Had you tried to assign it to a char instead, one of the letters (I can't recall which way it works) would have been dropped.


                    "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                    1 Reply Last reply
                    0
                    • CPalliniC CPallini

                      toxcct wrote:

                      'pp' is not a valid character,

                      it is a valid (though discouraged) multicharacter constant, see [^].

                      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

                      R Offline
                      R Offline
                      Raj Prathap
                      wrote on last edited by
                      #10

                      Sorry for replying after so many days.. it was Deevali in India and I was in vacation. Thanks a lot for the link. It was quite helpful. Pratap

                      CPalliniC 1 Reply Last reply
                      0
                      • R Raj Prathap

                        Sorry for replying after so many days.. it was Deevali in India and I was in vacation. Thanks a lot for the link. It was quite helpful. Pratap

                        CPalliniC Offline
                        CPalliniC Offline
                        CPallini
                        wrote on last edited by
                        #11

                        :-D

                        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

                        In testa che avete, signor di Ceprano?

                        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