On Sun, Oct 7, 2018 at 7:25 PM,  <bruceesm...@gmail.com> wrote:
>
> The header file smi.h from libsmi (https://github.com/mikeowens/libsmi)
> declares a typedef using "long double"
>
> typedef long double             SmiFloat128;
>
> In Go versions prior to 1.11, programs using smi.h compiled without error.
> In Go 1.11, cgo calls out "long double" as "unexpected". Here is that
> changed behaviour:
>
> bruce@calochilus:/tmp$ go version
> go version go1.11 linux/amd64
> bruce@calochilus:/tmp$ go build longdouble.go
> # command-line-arguments
> -: unexpected: 16-byte float type - long double
> bruce@calochilus:/tmp$ go1.10/bin/go version
> go version go1.10.3 linux/amd64
> bruce@calochilus:/tmp$ go1.10/bin/go build longdouble.go
> bruce@calochilus:/tmp$ cat longdouble.go
> package main
>
> /*
> #cgo LDFLAGS: -lsmi
> #include <stdlib.h>
> #include <smi.h>
> */
> import "C"
>
> import (
> "fmt"
> )
>
> type SmiType struct {
> smiType *C.struct_SmiType
> }
>
> func main() {
> fmt.Println("Hello")
> }
> bruce@calochilus:/tmp$
>
> So this raises two questions for me:
>
> a) is it a bug that the error message does not include a line number (the
> code in cmd/cgo/gcc.go tries to print a line number)

Yes.  It would be helpful if you could open an issue, ideally one with
a test case that does not require external header files.  Thanks.

> b) what is a 'best practice' approach to handling such an incompatible
> C-type?

If you are passing arguments of type SmiType, use a tiny C wrapper to
convert from double to SmiType when calling the real C function.

If it's a struct field, there isn't really any best practice.  Avoid
referring to the struct from Go, I guess.


Note that I don't know why this problem would be new in Go 1.11.  It
seems more likely due to some change in the C compiler on your system.
It's possible that 1.11 is somehow invoking the C compiler
differently, but I can't recall any change that would cause that.

Ian

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to