On Wed, 2020-09-09 at 12:19 +0200, Jan Mercl wrote:
> 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.
>
I get the following
```
C alignof struct s: 8
Go alignof struct s: 8
Go alignof S: 8
~/cznic $ go version
go version go1.15.1 linux/arm64
~/cznic $ uname -a
Linux bildr 4.19.0-10-arm64 #1 SMP Debian 4.19.132-1 (2020-07-24)
aarch64 GNU/Linux
```
I have an arm64 linux running on my pi, maybe the armv7l behaviour is
different.
Dan
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/da8da3f14f311a23ab0191d7e8ba130a068c73b8.camel%40kortschak.io.