How to access 16 bits

Hi, I have problem putting a value to 16 bits variable. Here is, how I am doing it.

1
2
3
4
5
6
7
8
9
10
typedef unsigned char UCHAR;
typedef UCHAR * ID_PTR;

unsigned short int myclass[5];
const ID_PTR  arr16_bit[5] = {
                               (UCHAR *) &myclass[0],
                               (UCHAR *) &myclass[1],
                               (UCHAR *) &myclass[2],
                               (UCHAR *) &myclass[3],
                             };

Now accessing the myclass like this.

*(*(arr16_bit + 2)) = 65000;

I can access the array, but the 65000 is cut to 8 bits. Why?
/thanks
kursist
Last edited on
closed account (z05DSL3A)
try changing

typedef UCHAR * ID_PTR;

to

typedef unsigned short int * ID_PTR;

1
2
3
4
5
6
7
8
    unsigned short int myclass[5];
    const ID_PTR  arr16_bit[5] = {
                               (ID_PTR) &myclass[0],
                               (ID_PTR) &myclass[1],
                               (ID_PTR) &myclass[2],
                               (ID_PTR) &myclass[3],
                             };
    *(*(arr16_bit + 2)) =  65000;
Last edited on
Thanks for reply,


1
2
3
4
5
6
7
8
9
10
typedef unsigned int UINT;
typedef UINT* ID_PTR;

unsigned short int myclass[5];
const ID_PTR  arr16_bit[5] = {
                               (UINT*) &myclass[0],
                               (UINT*) &myclass[1],
                               (UINT*) &myclass[2],
                               (UINT*) &myclass[3],
                             }; 


The problem still exist.
closed account (z05DSL3A)
Okay,

myclass is an array of 'unsigned short int's and 'arr16_bit' is an array of pointers to the elements of myclass. So they must be pointers to the same type: 'unsigned short int'

1
2
3
4
5
6
7
8
9
10
typedef unsigned short int SUINT;
typedef SUINT* ID_PTR;

SUINT myclass[5];
const ID_PTR  arr16_bit[5] = {
                               (ID_PTR) &myclass[0],
                               (ID_PTR) &myclass[1],
                               (ID_PTR) &myclass[2],
                               (ID_PTR) &myclass[3],
                             };


Is that clearer?
Last edited on
Thanks, This solved the problem.

1
2
3
unsigned int* ptr =(unsigned int *)*(arr16_bit + 5);
	
 *ptr = 10000;


;)
Last edited on
Topic archived. No new replies allowed.