SoFunction
Updated on 2025-03-01

Go language realizes the sharing of code for machine size and end judgment


package main  
 
import (  
    "fmt" 
    "unsafe" 
)  
 
const N int = int((0))  
 
func main() {  
    x := 0x1234  
    p := (&x)  
    p2 := (*[N]byte)(p)   
    if p2[0] == 0 {  
("This machine: Big endian")
    } else {  
("This machine: Little End")
    }