Cgo is used pretty heavily in Gorgonia. Here are some Cgo guidelines that I've come up with and used over the years:
-
Use astyle to fmt your C code. This is the command to use:
astyle --style=google -lineend=linux --indent=tab --indent-switches --align-pointer=type --align-reference=name --delete-empty-lines
. Yes, the choices are a bit weird, but it makes C more like Go code, which is readable af. -
When passing Go slices to a C function, pass a splatted fat pointer. What I mean by this is to do something like this (cap is optional but recommended):
void foo(double* sliceF64, int len, int cap) { }
-
Brackets are your friends. It's tempting to write this:
if (foo) bar() ```. Don't. Write shis instead: ```c if (foo) { bar() }
#Go Assembly#
When writing Go Assembly, use asmfmt