Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type translation does not respect systems data model #138

Closed
bearsh opened this issue Nov 17, 2022 · 1 comment
Closed

Type translation does not respect systems data model #138

bearsh opened this issue Nov 17, 2022 · 1 comment

Comments

@bearsh
Copy link
Contributor

bearsh commented Nov 17, 2022

c-fo-go has a fixed type mapping to map c types to go types. this is defined in

var builtinCTypeMap = CTypeMap{

the base for this mapping is https://en.wikipedia.org/wiki/C_data_types which is based on the c standard. the problem on these mapping are, they do not account for the data model the system uses.

For example a long int has to be, according to the standard at least 32bit, but on today's 64bit processors it's 64bit as well. at least on x86_64-linux-gnu, a int64_t is defined as long int and not, as one may expect, as long long int. therefor c-for-go translates this int64_t to golang's int32 instead of int64.

I suggests the translations map should also consider the data model the user expect to use. There's already an Arch settings in the yaml file which may be used. Maybe an OS setting is also needed. For a definition on data models and datatype size, the cpp reference provides a overview at https://en.cppreference.com/w/cpp/language/types

see also #120

bearsh added a commit to bearsh/c-for-go that referenced this issue Nov 17, 2022
fortunately modernc.org/cc already has this information. An uptate to
v4.1.0 is needed as otherwise ABI.Types is not public.

Issue: xlab#138

Signed-off-by: Martin Gysel <me@bearsh.org>
bearsh added a commit to bearsh/c-for-go that referenced this issue Nov 17, 2022
fortunately modernc.org/cc already has this information. An uptate to
v4.1.0 is needed as otherwise ABI.Types is not public.

Issue: xlab#138

Signed-off-by: Martin Gysel <me@bearsh.org>
@xlab
Copy link
Owner

xlab commented Nov 18, 2022

Thank you so much for digging into this and sending a PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants