a question about constant

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • phoenix_keeper

    #1

    a question about constant

    Why the value of 'ab\0\0' is 0x00616200, rather than 0x61620000 ?
    The workset is win2k + VC6.

    Any help would be appreciated.

    Thanks.

    CJ

  • Keith Thompson

    #2
    Re: a question about constant

    "phoenix_keeper " <m.phoenix.keep er@gmail.comwri tes:
    Why the value of 'ab\0\0' is 0x00616200, rather than 0x61620000 ?
    The workset is win2k + VC6.
    >
    Any help would be appreciated.
    The value of any character constant containing more than one character
    is implementation-defined. You should consult the documentation for
    your compiler. Better yet, you should avoid using such character
    constants; they're extremely non-portable.

    --
    Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.

    Comment

    • Thomas Matthews

      #3
      Re: a question about constant

      phoenix_keeper wrote:
      Why the value of 'ab\0\0' is 0x00616200, rather than 0x61620000 ?
      The workset is win2k + VC6.
      >
      Any help would be appreciated.
      >
      Thanks.
      >
      CJ
      >
      Research the term "Little Endian".


      --
      Thomas Matthews

      C++ newsgroup welcome message:

      C++ Faq: http://www.parashift.com/c++-faq-lite
      C Faq: http://www.eskimo.com/~scs/c-faq/top.html
      alt.comp.lang.l earn.c-c++ faq:

      Other sites:
      http://www.josuttis.com -- C++ STL Library book
      http://www.sgi.com/tech/stl -- Standard Template Library

      Comment

      • J. J. Farrell

        #4
        Re: a question about constant


        phoenix_keeper wrote:
        Why the value of 'ab\0\0' is 0x00616200, rather than 0x61620000 ?
        The workset is win2k + VC6.
        Because that's the value that the compiler you are using chose to give
        it. The value of a character constant containing more than one
        character is defined by the implementation. The algorithm they use is
        supposed to be specified in the compiler's documentation. If you want
        to know why they chose the algorithm they did, you'll have to ask the
        maker of the compiler.

        Comment

        • Rod Pemberton

          #5
          Re: a question about constant


          "Thomas Matthews" <Thomas_Hates_S pam@cox.network wrote in message
          news:44DBF084.5 080501@cox.netw ork...
          phoenix_keeper wrote:
          Why the value of 'ab\0\0' is 0x00616200, rather than 0x61620000 ?
          The workset is win2k + VC6.

          Any help would be appreciated.

          Thanks.

          CJ
          >
          Research the term "Little Endian".
          >
          No...

          Let's ignore for a moment the fact that it is a character constant and not a
          string constant, as KT pointed out.

          The last value in the OP's question: 0x61620000 is "Big Endian." But, the
          first value(0x0061620 0) is _neither_ "Little Endian" (0x00006261) or "Big
          Endian" (0x61620000) (as they are currently defined, i.e, no remarks on PDPs
          please...). The fact that his value 0x00616200 has 'a' before 'b' and isn't
          properly "Big Endian", indicates something else is going on (see KTs post).


          Rod Pemberton


          Comment

          • phoenix_keeper

            #6
            Re: a question about constant

            yeah, Thank you all :)

            Comment

            Working...