Scramble is a C preprocessor which allows to write C code which looks a bit like Python code with a full Python3 environment available for meta programming. That is, no semantics at all are changed - when using Scramble you still write C code. But it has a syntax more similar to Python.

Similar (and better) projects:


Get latest scramble from here.


Browse the source code.


Scramble is used like this: -i -c output.c -h output.h -n name

For example, if you have a file, then you could run: -i src/ -c build/c/main.c -h build/h/main.h -n main

And if your src/main.c would look like to the left, the resulting files would look like to the right (The red color indicates what the -n options does):


import stdio, string, math

int def main(int argc, char **argv):
    if argc == 2:
        printf("%f\n", sin(strtod(argv[1]))
        return 0
        fprintf(stderr, "Need exactly one argument!\n")
        return 1


#include "main.h"

int main(int argc, char **argv)
    if (argc == 2) {
        printf("%f\n", sin(strtod(argv[1]));
        return 0;
    else {
        fprintf(stderr, "Need exactly one argument!\n");
        return 1;


#ifndef _MAIN_

#include "stdio.h"
#include "string.h"
#include "math.h"

extern int main(int argc, char **argv);



usage: scramble [-?] [-i INPUT] [-c CFILE] [-C] [-h HFILE] [-n NAME]
                [-p PREFIX] [-N] [-s SFILE] [--noc99] [-j JOIN [JOIN ...]]
                [-o OUTPUT] [-t CTYPES]

optional arguments:
  -?, --help
  -i INPUT, --input INPUT
                        input file
  -c CFILE, --cfile CFILE
                        c output file
  -C, --comments        keep comments
  -h HFILE, --hfile HFILE
                        h output file
  -n NAME, --name NAME  module name
  -p PREFIX, --prefix PREFIX
                        header guard prefix
  -N, --no-lines        don't generate #line directives
  -s SFILE, --sfile SFILE
                        intermediate code output file
  --noc99               do not use C99
  -j JOIN [JOIN ...], --join JOIN [JOIN ...]
                        files to join
  -o OUTPUT, --output OUTPUT
                        source code output file
  -t CTYPES, --ctypes CTYPES
                        ctypes output file


All C, C++ and Python keywords basically are also Scramble keywords. The following control flow constructs are used by scramble: while,, do...while, for X while Y with Z [for (X; Y; Z) in C],, if...elif...else, label [: in C], goto.

And these declarations: class [struct in C], def, enum, global, import, macro [#define in C], static, struct, typedef, union.

These Python operators are used instead of the C++ ones: and [&& in C], max, min, not [! in C], or [|| in C].

And there's a few new constants: True, False, None.


In general, here is what scramble will do:

More stuff (might change?)

Valid XHTML 1.0 Strict