xlab / c-for-go

Automatic C-Go Bindings Generator for Go Programming Language
https://c.for-go.com
MIT License
1.5k stars 119 forks source link

How to keep int as int? #130

Closed TheFern2 closed 2 years ago

TheFern2 commented 2 years ago

I'd like to keep c int as go int, instead of int32 to make it more portable.

Can this be done?

xlab commented 2 years ago

In C int means 32-bit, if you use int in Go on a 64-bit machine, it will be long in C, which is different type.

Usually advanced API headers don't use those types as-is, and use stdint.h, which also adds strict type.

Anyway, I think proper way to do it is to make a hand-made wrapper around generated bindings.

TheFern2 commented 2 years ago

Ah ok appreciate the response, nvm if c int is always 32bits then it makes sense to leave it as int32. I was originally under the impression that it could be both 32, and 64bits.