AutoC is a collection of Ruby modules dedicated to the task of automatic generation of C source code.

Currently AutoC consists of two parts:

  • AutoC::Code - generic C multi-source module generator.

  • AutoC::Collection - strongly-typed data structure generators similar to the C++ STL container classes.

Avaliable data container generators

  • Vector<E>

  • List<E>

  • Queue<E>

  • HashSet<E>

  • HashMap<K,E>

  • TreeSet<E>

  • TreeMap<K,E>

Available miscellaneous generated types

  • String


AutoC is an open-source software. The complete source code is available in the code repository. Binary distributions can be downloaded from the SourceForge download page. The Ruby GEM can be obtained from the RubyGems download page or fetched directly via

$ gem install autoc


A complete documentation is available in HTML form browseable online.

Quick start

Here is a sample usage of AutoC to create a strongly-typed list container for int data type similar to the C++'s std::forward_list<int> template class.

Install the AutoC gem into the Ruby runtime

$ gem install autoc

Create a Ruby script `int_list.rb` containing the appropriate definitions.

require "autoc"
AutoC::Module.generate!(:Containers) do |m|
        m <<, :type => "int")

Call Ruby to generate the C source code.

$ ruby int_list.rb

This will emit the module definition header file `containers_auto.h` accompanied by the module implementation source file `containers_auto.c`.

Create a C source code `main.c` which uses the generated module.

#include <stdio.h>
#include "containers_auto.h"
int main(int argc, char** argv) {
        IntList list;
        IntListPush(&list, 1);
        IntListPush(&list, 2);
        IntListPush(&list, 3);
        printf("size=%d\n", IntListSize(&list));
        return 0;

The code above creates a list of integers data container on stack, puts three integer values into it, prints the container’s size and finally destroys the container.

Build the sample executable.

$ cc -o runme main.c containers_auto.c


Happy hacking and have fun!

Oleg A. Khlybov <>