Can someone point out a Go to C compiler to me, or does indeed none exist? A lengthy web search turned up nothing for me.
In particular, I am looking for an open source Go-to-C compiler that can be built for Linux.
Software Recommendations Stack Exchange is a question and answer site for people seeking specific software recommendations. It only takes a minute to sign up.Sign up to join this community
If you want the greatest cross platform support with least effort then Go is a great choice.
While there may be some C compilers for a few platforms that Go does not support, C is actually not nearly as cross platform friendly as you'd think (or was originally hopped).
In particular the Go standard library is built so that it supports the platforms that Go supports by including and automatically switching between platform specific implementations. These alternate implementations are automatically selected for you by the Go compiler at build time.
C has no equivalent mechanism. Which underscores why this was an important feature for Go's multi-platform and cross compilation support.
For example, consider the
path/filepath package in Go. It automatically switches between backward or forward slashes ("\","/") when working with paths depending on if the the compile target is Windows or not.
This mechanism is lost if you were to first compile Go to C then compile on the target platform, because at Go to C compile time the target platform is still unknown. This means that contrary to your expectations, cross compiling to C would reduce Go's cross platform support, not improve it.
All of that being said, you may want to check out the bblfsh project:
Bblfsh is essentially an Abstract Syntax Tree cross compiler. There are C++ an Go drivers for Bblfsh, but I don't see one for C. One can compile directly from the language AST, or even write the source code that would generate the AST.