Don't understand the data structure bitter AH
The Union occupies only one memory space in memory, the size of which is determined by the largest data type in the Union, and when the Union is initialized, the value of the Union is determined by the last valid parameter
' Created on
2012-9-9
@author: Jincheng ' '
ctypes import *
print "AAA:"
value = Raw_ Input ()
V=int (value)
Vv=long (value)
Vvv=value
Class aaa (Union):
_fields_=[
("AAA", c_ int),
("BBB", C_long),
("CCC", C_char), ]
print "aaaaaaa:%s"%value
a=aaa (V,VV,VVV)
Print "AAA:%d"%a.aaa
print "BBB:%ld"%a.bbb
print "CCC:%s"%A.CCC
Test1
C:\python27>python D:\jincheng\workspace\GrayHatPython\chapter1.py
AAA:
6
aaaaaaa:6
AAA:
bbb:54
Ccc:6
Test2
C:\python27>python D:\jincheng\workspace\GrayHatPython\chapter1.py
AAA:
aaaaaaa:66
aaa:13878
bbb:13878
ccc:66
Modify
From ctypes import *
print "AAA:"
value = Raw_input ()
v=int (value)
print "v%d"%v
print "BBB:"
Val=raw_input ()
Vv=long (val)
Vvv=value
Class aaa (Union):
_fields_=[
("AAA", C_int),
(" BBB ", C_long),
(" CCC ", C_char * 6), ]
print" aaaaaaa:%s "%value
a=aaa (V,VV)
s=a.aaa
SS =int (s)
print "ss%d"%ss
print "AAA:%d"%a.aaa
print "BBB:%ld"%a.bbb
print "CCC:%s"%A.CCC
Test
D:\python27>python d:\demo.py
AAA:
v
-BBB:
aaaaaaa:66
SS
aaa:55
bbb:55
ccc:7