Observation:

pi@raspberrypi:~/src/tmp.tmp $ go version
go version go1.15.1 linux/arm
pi@raspberrypi:~/src/tmp.tmp $ cat main.go
package main

/*

struct s {
        long long i;
} x;

size_t align() {
        return _Alignof(struct s);
}

*/
import "C"

import (
        "fmt"
        "unsafe"
)

type S struct {
        i int64
}

func main() {
        fmt.Printf(" C alignof struct s: %v\n", C.align())
        fmt.Printf("Go alignof struct s: %v\n",
unsafe.Alignof(C.struct_s{}))
        fmt.Printf("Go alignof        S: %v\n", unsafe.Alignof(S{}))
}
pi@raspberrypi:~/src/tmp.tmp $ go run main.go
 C alignof struct s: 8
Go alignof struct s: 4
Go alignof        S: 4
pi@raspberrypi:~/src/tmp.tmp $ uname -a
Linux raspberrypi 4.19.66-v7+ #1253 SMP Thu Aug 15 11:49:46 BST 2019 armv7l
GNU/Linux
pi@raspberrypi:~/src/tmp.tmp $

My code relies on all the numbers being the same, ie. that Go will report
the same as C for both C.struct_s{} and S{}.
AFAICT Go and C agree on struct layout on linux/{amd64,386} perfectly in
all cases I've tested (thousands probably).

Is this a bug or are my expectations ill founded?

Thanks in advance for any insights.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAA40n-Vdqc6QLzsYWgmzCRMvChiLbP1geLTWLpqF8Pw-ygqrAA%40mail.gmail.com.

Reply via email to