Hello World
GX is a statically-typed, procedural language that compiles to C and then to a native binary. No garbage collector, no hidden runtime, no surprises. You write it, you own it.
Let’s write your first program.
Your First Program
fn main() {
print("Hello, world!\n")
}
Every GX program starts with fn main(). The print function outputs text, and \n adds a newline.
Try it — Paste the code above into the Playground and hit Run.
Compiling and Running
Save the code as hello.gx, then:
gx hello.gx -o hello
./hello
That’s it. GX compiles your source to C, then passes it through a C compiler to produce a native executable. One command, one binary.
What Just Happened?
hello.gx --> GX Compiler --> hello.c --> C Compiler --> hello.exe
GX doesn’t interpret your code. It generates clean, readable C and compiles that into a native binary. The result runs at full native speed with no runtime overhead.
A Bit More Interesting
fn main() {
var name = "GX"
var version = 2
print("Welcome to {name} v{version}!\n")
}
GX supports string interpolation — put any variable inside {} and it gets embedded directly in the string. No format specifiers, no concatenation gymnastics.
Notice something? Semicolons are optional in GX. Use them if you like, leave them out if you don’t. Both styles work.
Try it — Modify the name and version, then run it in the Playground.
Expert Corner
Why compile to C? C runs everywhere. By targeting C, GX inherits decades of battle-tested compilers (GCC, Clang, TCC), optimizers, and platform support without reinventing them. Your GX code benefits from -O2 optimizations that took thousands of engineers years to build.
The backend architecture is pluggable. The C backend is the default, but GX is designed to support LLVM, JavaScript, and WebAssembly backends. The Playground you just used? It compiles GX to JavaScript via the JS backend and runs it in your browser.
“No hidden allocations” means exactly that. If your program doesn’t call malloc, no memory gets allocated on the heap. This matters for game engines, embedded systems, and anywhere you need deterministic performance. You control every byte.