Advertisement · 728 × 90

Posts by Anton Zhiyanov

Post image

Made a small progress bar for the first release of Solod (a subset of Go that translates to C).

Not quite there yet, but a lot of work is already done!

18 hours ago 8 0 0 0
Post image

But sometimes, maps are really useful for small, local tasks like routing or counting.

So, I eventually made a stack-allocated version of the map[K]V built-in. It's lightweight and super fast — sometimes even faster than Go's map (which is already state-of-the-art).

5 days ago 1 0 0 0

When I designed Solod (a subset of Go that translates to C), I set a strict rule: no heap allocations in the language or built-ins (only in the standard library).

That meant no built-in maps.

5 days ago 0 0 1 0

Maps are essential in application development. But Go's stdlib uses maps very cautiously.

I've ported a dozen core Go packages to C so far and have encountered a map only a couple of times.

The fewer maps, the better!

6 days ago 0 0 0 0
Preview
Porting Go's strings package to C With allocators, benchmarks, and some optimizations.

Can a C port of the Go stdlib be faster than the original?

I was able to get a 2-4x speed boost with strings.Builder, but couldn't beat Go's substring search.

On porting, benchmarks, and optimization: antonz.org/porting-go-s...

1 week ago 0 0 0 0

Details: github.com/solod-dev/so...

1 week ago 0 0 0 0
Post image

Solod (a subset of Go that translates to C) shines when it comes to C interop. But it's also quite fast on regular Go code.

In this strings.Builder benchmark — a common, optimized case in Go — Solod performs 2-4 times faster.

And the binary is only 53K (vs. 1.6M with Go).

1 week ago 1 0 1 0
Advertisement
Post image

While porting Go's standard library to C, I try to avoid heap allocations as much as possible.

Of course, sometimes there's no way around them, like in os.ReadFile.

But often I can use local stack allocations or a buffer provided by the caller instead.

It's working pretty well.

1 week ago 1 0 0 0
Post image

If you stare into Go's stdlib long enough, you start seeing things.

Dark things. Things you weren't meant to see.

Like this function that uses variables named φ and β.

1 week ago 25 1 2 0
Post image

In today's crazy world, writing C is the only sane thing to do.

P.S. You don't need AI; you have AI in netdb.h.

2 weeks ago 5 0 0 0
Solod playground

Solod playground

Solod (a subset of Go that translates to C) now has an online playground!

I guess that means it's a real language now 😁

codapi.org/so

2 weeks ago 5 0 0 0
Preview
Porting Go's io package to C Interfaces, slices, multi-returns and alloca.

The "io" package is a core part of Go's standard library. Porting it to C was an interesting challenge.

I had to figure out how to handle slices, multiple return values, errors, and interfaces in C. But in the end, it worked out pretty well!

antonz.org/porting-go-io

2 weeks ago 9 0 0 0
Preview
Solod: Go can be a better C A subset of Go that transpiles to regular C, with zero runtime.

Could Go be a better C? I think so!

Meet Solod — a strict subset of Go that translates to C, without hidden memory allocations and with source-level interop.

antonz.org/solod

3 weeks ago 18 2 0 0

Such a terrible development 😐

4 weeks ago 1 0 0 0
Advertisement

Honestly, even with just the syntax, writing C has become more pleasant for me personally.

The end goal is also to port Go's stdlib.

So, it's not just about the syntax! :)

4 weeks ago 0 0 0 0

But it supports custom allocators, so a tracking allocator (once I write one) should help with temporal safety.

4 weeks ago 0 0 0 0

As for safety — not much too. Out-of-bounds — yes, use-after-free and dangling pointers — no. Using GCC/Clang sanitizer flags helps up to a point.

4 weeks ago 0 0 1 0

Not much so far. I started small, so right now it's just bytes, io, unicode, and a few others. I'd say it's more about adapting than reimplementing — most of the code works fine. But yeah, it's not exactly a walk in the park :)

4 weeks ago 0 0 1 0

The basic approach is this:

// panics on failure
func Alloc[T any](a Allocator) *T

// returns an error
func TryAlloc[T any](a Allocator) (*T, error)

Unfortunately, it's not as easy with stdlib, where a lot of functions allocate, and having Try-versions doubles the API surface. We'll see.

4 weeks ago 1 0 1 0

That's the whole point :) Why would I want a garbage collector when Go already has one?

The big idea is to bring the power of Go's standard library to C, so everyone can use it without any extra overhead.

4 weeks ago 2 0 1 0
Post image

Working on something crazy these days — using Go to write regular C code. Wish me luck :)

4 weeks ago 35 3 4 0

Thank you for sharing, Laurent!

1 month ago 1 0 0 0
Advertisement
Preview
(Un)portable defer in C Eight ways to implement defer in C.

How to implement "defer" keyword in C (allows to free memory and other resources correctly): implementations with C23/GCC, C11/GCC, GCC/Clang... - Blog Post by Anton Zhiyanov @antonz.org #Programming antonz.org/defer-in-c/

1 month ago 6 3 1 1
Preview
Allocators from C to Zig Exploring allocator design in C, C3, Hare, Odin, Rust, and Zig.

What makes modern systems languages stand out? Many things — but allocators are a big one.

Let's explore how Rust, Zig, Odin, C3, and Hare design their allocators, and then build one in C!

antonz.org/allocators

1 month ago 7 0 0 0
Preview
Go 1.26 interactive tour New with expressions, type-safe error checking, and faster everything.

Go 1.26 is out, and the announcement says:

"Over the next few weeks, follow-up blog posts will cover some of the topics in more detail. Check back later."

So you can wait a few weeks OR you can read my interactive Go 1.26 tour right away:

antonz.org/go-1-26

2 months ago 52 14 1 0
Preview
Valkey: A new hash table Designing a state-of-the art hash table

SwissTable, a high-performance open-addressing hash map originally developed by Google, is becoming more popular in the industry.

First, Rust adopted it for its HashMap type. Then Go started using SwissTable for its map type.

And now — Valkey. Pretty cool!

valkey.io/blog/new-has...

2 months ago 3 0 0 0
Post image

Fancy an allocator in C? It's not Zig, but it's honest work.

2 months ago 1 0 0 0
Preview
(Un)portable defer in C Eight ways to implement defer in C.

We don't need to wait for "defer" to be added to the C standard. We already have defer at home!

antonz.org/defer-in-c

2 months ago 1 0 0 0
Post image

The only two features I really miss in C at this point are namespaces and defer.

2 months ago 2 0 0 0
Post image

With Go 1.26, you can easily log to multiple targets (like stdout, a file, or a remote server) using just the standard library.

All thanks to slog.MultiHandler, which sends log records to any number of handlers you configure.

2 months ago 33 5 0 0