Hi,
I couldn't figure out how to properly type cast in this case:
$ cat -n type_cast.c
1 #include <stdio.h>
2
3 typedef unsigned char Byte;
4 typedef signed char Small_Int;
5
6 typedef struct _list
7 {
8 struct _list *np; /* Pointer to next */
9 struct _list *lp; /* Pointer to last */
10 Byte type;
11 union {
12 void *dp; /* Pointer to data */
13
14 /* These fields used for a small amount of data */
15 struct {
16 Byte d1;
17 Byte d2;
18 Byte d3;
19 Byte d4;
20 } bytes;
21
22 }data;
23
24 } List;
25
26 List *markedplace;
27 Small_Int i;
28
29 main(int argc,char * argv[])
30 {
31 i = 2;
32 markedplace->data.dp = NULL;
33 (Small_Int *)markedplace->data.dp = i;
34 }
$ gcc type_cast.c
type_cast.c: In function 'main':
type_cast.c:33: error: lvalue required as left operand of assignment
How should I fix it?
Thanks
--
Tong (remove underscore(s) to reply)
I couldn't figure out how to properly type cast in this case:
$ cat -n type_cast.c
1 #include <stdio.h>
2
3 typedef unsigned char Byte;
4 typedef signed char Small_Int;
5
6 typedef struct _list
7 {
8 struct _list *np; /* Pointer to next */
9 struct _list *lp; /* Pointer to last */
10 Byte type;
11 union {
12 void *dp; /* Pointer to data */
13
14 /* These fields used for a small amount of data */
15 struct {
16 Byte d1;
17 Byte d2;
18 Byte d3;
19 Byte d4;
20 } bytes;
21
22 }data;
23
24 } List;
25
26 List *markedplace;
27 Small_Int i;
28
29 main(int argc,char * argv[])
30 {
31 i = 2;
32 markedplace->data.dp = NULL;
33 (Small_Int *)markedplace->data.dp = i;
34 }
$ gcc type_cast.c
type_cast.c: In function 'main':
type_cast.c:33: error: lvalue required as left operand of assignment
How should I fix it?
Thanks
--
Tong (remove underscore(s) to reply)
Comment