import (
"fmt"
+ "math"
)
+type Shaper interface {
+ Area() float64
+}
+
+type Square struct {
+ slide float64
+}
+
+func (s *Square) Area() float64 {
+ return s.slide*s.slide
+}
+
+type Round struct {
+ radius float64
+}
+
+func (r *Round) Area() float64 {
+ return math.Pi*r.radius*r.radius
+}
+
+
+type Rectangular struct {
+ width float64
+ height float64
+}
+
+func (r *Rectangular) Area() float64 {
+ return r.width*r.height
+}
+
func main() {
defer fmt.Println("Program Exited...")
+ sq := Square{12.34}
+ rd := new(Round)
+ rd.radius = 9.99
+ rt := Rectangular{0.6, 0.8}
+
+ var shaper Shaper
+ shaper = &sq
+ fmt.Println("Square Slide", sq.slide, "Area", shaper.Area())
+
+
+ // rd is pointer
+ shaper = rd
+ fmt.Println("Round Radius", rd.radius, "Area", shaper.Area())
+
+ shaper = &rt
+ fmt.Println("Rectangular Width", rt.width, "Height", rt.height, "Area", shaper.Area())
}
import "fmt"
import "time"
import "math/rand"
+import "reflect"
+
+type Private struct {
+ data string
+}
type Vertex struct {
X int
- Y int
+ Y int "Y Pos" // 字段名可以带标签
+ string "Anonymous Field" // 匿名字段
+ Private "Anonymous Struct" // 在一个结构体中对于每一种数据类型只能有一个匿名字段
+ s string
}
func main() {
rand.Seed(time.Now().UnixNano())
- v := Vertex{1, 2}
+ v := Vertex{X:1, Y:2}
+
+ v.string = "anonymouse string field"
+ v.data = "anonymouse struct field data"
fmt.Println(v)
- fmt.Println(Vertex{0xABC, 0xCBA})
+ fmt.Println(Vertex{X:0xABC, Y:0xCBA})
+ //fmt.Println(Vertex{0xAA, 0xBB, "anonymous string", {"anonymous data"}, "dd", "FF"})
+ fmt.Println(Vertex{0xAA, 0xBB, "anonymous string", Private{"anonymous data"}, "a"})
// 通过指针间隔访问的过程是透明的
p := &v
fmt.Println(v)
v.X, v.Y = p.Y, p.X
fmt.Println(v.X, v.Y)
+
+ // 遍历结构
+ fmt.Printf("%10v %16v %16v %10v %10v %16v %10v\n", "Name", "Type", "Tag", "Offset", "Index", "PkgPath", "Anonymous")
+ for i := 0; i < reflect.TypeOf(v).NumField(); i++ {
+ Field := reflect.TypeOf(v).Field(i)
+ fmt.Printf("%10v %16v %16v %10v %10v %16v %10v\n", Field.Name, Field.Type, Field.Tag, Field.Offset, Field.Index, Field.PkgPath, Field.Anonymous)
+ }
}
"CR4.OSFXSR is available)")
TEST_FEATURE(fv, 25, "SSE: SSE Extensions")
TEST_FEATURE(fv, 26, "SSE2: SSE2 Extensions")
- //TEST_FEATURE(fv, 27, "Reserved")
+ TEST_FEATURE(fv, 27, "SS: CPU Cache Supports Self-Snoop")
TEST_FEATURE(fv, 28, "Hyper Threading Technology")
TEST_FEATURE(fv, 29, "TM: Thermal Monitor")
- //TEST_FEATURE(fv, 30, "Reserved")
+ TEST_FEATURE(fv, 30, "IA64 Processor Emulating X86")
TEST_FEATURE(fv, 31, "PBE: Pending Break Enable")
-
-
-
-
+ fv = r.ecx;
+ printf("-------------\n");
+ TEST_FEATURE(fv, 0, "SSE3: Prescott New Instructions-SSE3 (PNI)")
+ TEST_FEATURE(fv, 1, "PCLMULQDQ Support")
+ TEST_FEATURE(fv, 2, "64Bit Debug Store (EDX Bit21)")
+ TEST_FEATURE(fv, 3, "MONITOR and MWAIT Instructions (SSE3)")
+ TEST_FEATURE(fv, 4, "CPL Qualified Debug Store")
+ TEST_FEATURE(fv, 5, "VMX: Virtual Machine eXtensions")
+ TEST_FEATURE(fv, 6, "SMX: Safer Mode Extensions")
+ TEST_FEATURE(fv, 7, "EST: Enhanced SpeedStep")
+ TEST_FEATURE(fv, 8, "TM2: Thermal Monitor 2")
+ TEST_FEATURE(fv, 9, "SSSE3: Supplemental SSE3 Instructions")
+ TEST_FEATURE(fv, 10, "L1 Context ID")
+ TEST_FEATURE(fv, 11, "SDBG: Silicon Debug Interface")
+ TEST_FEATURE(fv, 12, "FMA: Fused Multiply-add (FMA3)")
+ TEST_FEATURE(fv, 13, "CX16: CMPXCHG16B Instructions")
+ TEST_FEATURE(fv, 14, "XTPR: Can Disable Sending Task Priority Messages")
+ TEST_FEATURE(fv, 15, "PDCM: Perfmon & Debug Capability")
+ //TEST_FEATURE(fv, 16, "Reserved")
+ TEST_FEATURE(fv, 17, "PCID: Process Context Identifiers (CR4 bit 17)")
+ TEST_FEATURE(fv, 18, "DCA: Direct Cache Access for DMA Writes")
+ TEST_FEATURE(fv, 19, "SSE4.1: SSE4.1 Instructions")
+ TEST_FEATURE(fv, 20, "SSE4.2: SSE4.2 Instructions")
+ TEST_FEATURE(fv, 21, "X2APIC: x2APIC Support")
+ TEST_FEATURE(fv, 22, "MOVBE: MOVBE Instruction (big-endian)")
+ TEST_FEATURE(fv, 23, "POPCNT: POPCNT Instruction")
+ TEST_FEATURE(fv, 24, "TSC-DEADLINE: APIC Supports One-Shot Operation Using a TSC Deadline Value")
+ TEST_FEATURE(fv, 25, "AES: AES Instruction Set")
+ TEST_FEATURE(fv, 26, "XSAVE: XSAVE, XRESTOR, XSETBV, XGETBV")
+ TEST_FEATURE(fv, 27, "OSXSAVE: XSAVE Enabled by OS")
+ TEST_FEATURE(fv, 28, "AVX: Advanced Vector Extensions")
+ TEST_FEATURE(fv, 29, "F16C: F16C (Half-Precision) FP Support")
+ TEST_FEATURE(fv, 30, "RDRND: RDRAND (On-Chip Random Number Generator) Support")
+ TEST_FEATURE(fv, 31, "HYPERVISOR: Running on a Hypervisor (Always 0 on a Real CPU, But Also With Some Hypervisors")
/**********************Get CPU's SERIAL Number*********************/