Bonjour,
la lecture des éléménts d'une structure me donne des fausses valeurs !!
Voici le code:
J'obtiens ceci:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 char buf[]={0x1A,0x1B,0x1C,0x33,0x51,0x12,0x34,0x56,0x78,0x01,0xA5,0xBC,0xEF}; //=================================================== typedef struct {char a[3]; short b; int c; char d; } MyStruct; //================== int main(){ MyStruct *x=buf; uart_init(); // hexstring(x->a[0]); hexstring(x->a[1]); hexstring(x->a[2]); hexstring(x->b); hexstring(x->c); hexstring(x->d); hexstring(buf[0]); hexstring(buf[1]); hexstring(buf[2]); hexstring(buf[3]); hexstring(buf[4]); hexstring(buf[5]); hexstring(buf[6]); hexstring(buf[7]); hexstring(buf[8]); hexstring(buf[9]); hexstring(buf[10]); hexstring(buf[11]); return(0);}
il me semble que l' element de type "short" est representé en memoire sur 4 octets et non pas 2 !!
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 0000001A -> bon 0000001B -> bon 0000001C -> bon 00001251 -> ?? en principe 33 51 ou 51 33 BCA50178 -> ?? en principe 12 34 56 78 ou 78 56 34 21 000000EF -> ?? en principe 01 0000001A -> tout OK 0000001B 0000001C 00000033 00000051 00000012 00000034 00000056 00000078 00000001 000000A5 000000BC
Comment rémedier à ça? svp.
Partager