2015-04-04

Appendix of Cgo and Go Type Mappings

I was working Cgo and wanted an equivalence chart for the C primitive types for reference. Since none exists, this is what I came up with for amd64 Linux.

There are a few caveats to be aware of:

  • Some of the aliases have sequence numbers associated with them to deduplicate their type names within the package namespace in which they were generated. This is to say, carefully understand what is expressed here before using verbatim.
  • If you are reading this page, you are presumed to understand struct alignment and padding.
  • This list was generated mostly through an automated means, with some by-hand reconcilation in places. Please do not hesitate to report any errors or typos (even though I have done a once-over already)!

The source that powers this listing is found here at github.com/matttproud/cgotypes. It is worth running the go tool cgo tool to get the intermediate output contained in the _obj directory:

$ go tool cgo main.go
$ ls _obj

Namely _obj/_cgo_gotypes.go will be of interest!


C TypeGo KindCgo AliasGo Fundamental
charint8_Ctype_charint8
signed charint8_Ctype_scharint8
unsigned charuint8_Ctype_unsignedcharuint8
shortint16_Ctype_shortint16
short intint16_Ctype_shortint16
signed shortint16_Ctype_shortint16
signed short intint16_Ctype_shortint16
unsigned shortuint16_Ctype_unsignedshortuint16
unsigned short intuint16_Ctype_unsignedshortuint16
intint32_Ctype_intint32
signed intint32_Ctype_intint32
unsigneduint32_Ctype_uintuint32
unsigned intuint32_Ctype_uintuint32
longint64_Ctype_longint64
long intint64_Ctype_longint64
signed longint64_Ctype_longint64
signed long intint64_Ctype_longint64
unsigned longuint64_Ctype_ulonguint64
unsigned long intuint64_Ctype_ulonguint64
long longint64_Ctype_longlongint64
long long intint64_Ctype_longlongint64
signed long longint64_Ctype_longlongint64
signed long long intint64_Ctype_longlongint64
floatfloat32_Ctype_floatfloat32
doublefloat64_Ctype_doublefloat64
long doublen/an/aunconvertable
boolbool_Ctype__Boolbool
unionarray[8]uint8the size directly reflects the underlying contents: [8]byte
structstruct_Ctype_struct___3struct {int; int64}
char foo[1]array[1]_Ctype_char[1]int8
signed char foo[1]array[1]_Ctype_schar[1]int8
unsigned char foo[1]array[1]_Ctype_unsignedchar[1]uint8
short foo[1]array[1]_Ctype_short[1]int16
short int foo[1]array[1]_Ctype_short[1]int16
signed short foo[1]array[1]_Ctype_short[1]int16
signed short int foo[1]array[1]_Ctype_short[1]int16
unsigned short foo[1]array[1]_Ctype_unsignedshort[1]uint16
unsigned short int foo[1]array[1]_Ctype_unsignedshort[1]uint16
int foo[1]array[1]_Ctype_int[1]int32
signed int foo[1]array[1]_Ctype_int[1]int32
unsigned foo[1]array[1]_Ctype_uint[1]uint32
unsigned int foo[1]array[1]_Ctype_uint[1]uint32
long foo[1]array[1]_Ctype_long[1]int64
long int foo[1]array[1]_Ctype_long[1]int64
signed long foo[1]array[1]_Ctype_long[1]int64
signed long int foo[1]array[1]_Ctype_long[1]int64
unsigned long foo[1]array[1]_Ctype_ulong[1]uint64
unsigned long int foo[1]array[1]_Ctype_ulong[1]uint64
long long foo[1]array[1]_Ctype_longlong[1]int64
long long int foo[1]array[1]_Ctype_longlong[1]int64
signed long long foo[1]array[1]_Ctype_longlong[1]int64
signed long long int foo[1]array[1]_Ctype_longlong[1]int64
float foo[1]array[1]_Ctype_float[1]float32
double foo[1]array[1]_Ctype_double[1]double
long double foo[1]n/an/aunconvertable
bool foo[1]array[1]_Ctype__Bool[1]bool
union foo[1]array[1][8]uint8the size directly reflects the underlying contents: [1][8]byte
struct foo[1]array[1]_Ctype_struct___5[1]struct{int32; int64}
char *fooptr*_Ctype_char*int8
signed char *fooptr*_Ctype_schar*int8
unsigned char *fooptr*_Ctype_unsignedchar*uint8
short *fooptr*_Ctype_short*int16
short int *fooptr*_Ctype_short*int16
signed short *fooptr*_Ctype_short*int16
signed short int *fooptr*_Ctype_short*int16
unsigned short *fooptr*Ctype_unsignedshort*uint16
unsigned short int *fooptr*Ctype_unsignedshort*uint16
int *fooptr*_Ctype_int*int32
signed int *fooptr*_Ctype_int*int32
unsigned *fooptr*_Ctype_uint*uint32
unsigned int *fooptr*_Ctype_uint*uint32
long *fooptr*_Ctype_long*int64
long int *fooptr*_Ctype_long*int64
signed long *fooptr*_Ctype_long*int64
signed long int *fooptr*_Ctype_long*int64
unsigned long *fooptr*_Ctype_ulong*uint64
unsigned long int *fooptr*_Ctype_ulong*uint64
long long *fooptr*_Ctype_longlong*int64
long long int *fooptr*_Ctype_longlong*int64
signed long long *fooptr*_Ctype_longlong*int64
signed long long int *fooptr*_Ctype_longlong*int64
float *fooptr*_Ctype_float*float32
double *fooptr*_Ctype_double*float64
long double *foon/an/aunconvertable
bool *fooptr*_Ctype__Bool*bool
union *fooptr*[8]uint8the size directly reflects the underlying contents: *[8]byte
struct *fooptr*_Ctype_struct___7*struct{int32; int64}
func *fooptr*[0]uint8*[0]byte
void ptrunsafe.Pointerunsafe.Pointerunsafe.Pointer
char foo[]array_Ctype_ary_char[0]int8
signed_char foo[]array_Ctype_ary_signed_char[0]int8
unsigned_char foo[]array_Ctype_ary_unsigned_char[0]uint8
short foo[]array_Ctype_ary_short[0]int16
short int foo[]array_Ctype_ary_short_int[0]int16
signed short foo[]array_Ctype_ary_signed_short[0]int16
signed short int foo[]array_Ctype_ary_signed_short_int[0]int16
unsigned short foo[]array_Ctype_ary_unsigned_short[0]uint16
unsigned short int foo[]array_Ctype_ary_unsigned_short_int[0]uint16
int foo[]array_Ctype_ary_int[0]int32
signed int foo[]array_Ctype_ary_signed_int[0]int32
unsigned foo[]array_Ctype_ary_unsigned[0]uint32
unsigned int foo[]array_Ctype_ary_unsigned_int[0]uint32
long foo[]array_Ctype_ary_long[0]int64
long int foo[]array_Ctype_ary_long_int[0]int64
signed long foo[]array_Ctype_ary_signed_long[0]int64
signed long int foo[]array_Ctype_ary_signed_long_int[0]int64
unsigned long foo[]array_Ctype_ary_unsigned_long[0]uint64
unsigned long int foo[]array_Ctype_ary_unsigned_long_int[0]uint64
long long foo[]array_Ctype_ary_long_long[0]int64
long long int foo[]array_Ctype_ary_long_long_int[0]int64
signed long long foo[]array_Ctype_ary_signed_long_long[0]int64
signed long long int foo[]array_Ctype_ary_signed_long_long_int[0]int64
float foo[]array_Ctype_ary_float[0]float32
double foo[]array_Ctype_ary_double[0]float64
long double[]n/an/aunconvertable
bool foo[]array_Ctype_ary_bool[0]bool
union foo[]array_Ctype_ary_unionthe size directly reflects the underlying contents: [0][8]byte
struct foo[]array_Ctype_ary_struct[0]struct{int32; int64}

follow us in feedly

No comments :

Post a Comment

 

None of the content contained herein represents the views of my employer nor should it be construed in such a manner. . All content is copyright Matt T. Proud and may not be reproduced in whole or part without expressed permission.