C

Low-level systems programming language

Overview

C is a powerful, low-level programming language that provides direct access to memory and hardware. It's the foundation for many operating systems, embedded systems, and performance-critical applications.

With run, you can compile and execute C code using GCC or Clang without managing makefiles or build systems.

Language Aliases

Supported Aliases
run c "#include <stdio.h>
int main() { printf("Hello\n"); return 0; }"
run gcc "#include <stdio.h>
int main() { printf("Hello\n"); return 0; }"
run clang "#include <stdio.h>
int main() { printf("Hello\n"); return 0; }"
Output
Hello
Hello
Hello

Basic Usage

Hello World
run c "#include <stdio.h>
int main() {
    printf("Hello, World!\n");
    return 0;
}"
Output
Hello, World!
Simple Variables
run c "#include <stdio.h>
int main() {
    int x = 42;
    printf("Value: %d\n", x);
    return 0;
}"
Output
Value: 42

Piping Code to run

You can pipe C code to run using echo or cat. If you encounter issues with format specifiers being interpreted by your shell, use here-documents instead:

Terminal
echo '#include <stdio.h>
int main() { printf("Hello\n"); return 0; }' | run c
Terminal
cat <<'EOF' | run c
#include <stdio.h>
int main() {
    int c = 10;
    printf("%d\n", c);
    return 0;
}
EOF

REPL Mode - Interactive C

Start an interactive C REPL with 'run c'. The REPL is stateful within the session:

Terminal
$ run c
run universal REPL. Type :help for commands.
c>>> #include <stdio.h>
c>>> int x = 10;
c>>> printf("%d\n", x);
10
c>>> int square(int n) { return n * n; }
c>>> printf("%d\n", square(5));
25
c>>>

REPL Behavior - Stateful

C's REPL is STATEFUL within a single interactive session:

• Start REPL with 'run c'

• Includes, functions, and variables persist at the c>>> prompt

• Each command builds on previous definitions in that session

• Separate 'run c "code"' invocations are independent compilations

⚠️ Troubleshooting: printf Command Issues

If you use the shell's printf command to pipe C code, it may interpret format specifiers like %d and escape sequences, corrupting your code. This causes compilation errors like 'missing terminating quote'.

Solution: Use here-documents with cat <<'EOF' to preserve your C code exactly as written.

Terminal
printf "int c = 10;
printf("%d\n", c);
" | run c
Terminal
cat <<'EOF' | run c
int c = 10;
printf("%d\n", c);
EOF