Casting a char to an unsigned short: what happens behind the scenes?

Posted by hb on Stack Overflow See other posts from Stack Overflow or by hb
Published on 2008-12-31T09:41:09Z Indexed on 2010/03/26 21:23 UTC
Read the original article Hit count: 300

Filed under:
|
|

Given this field:

char lookup_ext[8192] = {0}; // Gets filled later

And this statement:

unsigned short *slt = (unsigned short*) lookup_ext;

What happens behind the scenes?

lookup_ext[1669] returns 67 = 0100 0011 (C), lookup_ext[1670] returns 78 = 0100 1110 (N) and lookup_ext[1671] returns 68 = 0100 0100 (D); yet slt[1670] returns 18273 = 0100 0111 0110 0001.

I'm trying to port this to C#, so besides an easy way out of this, I'm also wondering what really happens here. Been a while since I used C++ regularly.

Thanks!

© Stack Overflow or respective owner

Related posts about c

    Related posts about c#