a question about constant

P

phoenix_keeper

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

Any help would be appreciated.

Thanks.

CJ
 
K

Keith Thompson

phoenix_keeper said:
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.
 
T

Thomas Matthews

phoenix_keeper said:
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:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
 
J

J. J. Farrell

phoenix_keeper said:
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.
 
R

Rod Pemberton

Thomas Matthews said:
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(0x00616200) 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top