Downloading the compiler
main.c

          
        

Compiler options

Help

Running a program

Write your program in the editor and press Run or F10. To check a program without running it, choose Execute, then Compile only (F9). Errors and warnings are underlined in the editor and listed above the output; click one to jump to its line.

Anything the program reads with scanf, getchar or fgets must be typed into the Input box before you press Run. The program reads it from there, because it cannot stop and wait for the keyboard while it runs. If the program asks for two numbers, type both, separated by a space or on separate lines.

Files

Open the Files tab beside Input to add data files, or to create one and type into it. Your program opens them by name, for example fopen("data.txt", "r"). Files the program writes with fopen(..., "w") are listed under the output, where you can view them, download them, or keep them as input for the next run.

Keyboard shortcuts

F10 or Ctrl+Enter
Compile and run
F9
Compile only
Ctrl+S
Save as a .c file
Ctrl+O
Open a .c file
Ctrl+F
Find and replace
F3 or Ctrl+G
Find next
Ctrl+Alt+G
Go to line
Ctrl+/
Comment or uncomment lines
Ctrl+Z, Ctrl+Y
Undo, redo
Esc
Close a menu or restore an enlarged panel

On a Mac, use Cmd in place of Ctrl.

What does not work here

Programs run in a sandbox inside the browser, so a few things that work on a desktop compiler are not available: conio.h and graphics.h (they belong to old Turbo C), system(), threads, networking, and reading the keyboard while the program runs. Everything in the standard C library, including math.h, string.h, stdlib.h and file input and output, works as usual.

About C Lab

CLab: powered by Clang and WebAssembly, a browser-native offline C compiler

C Lab is a C editor and compiler that runs entirely inside your web browser.

It was made by Mainul Hossain for students learning C and numerical methods, so that a program can be written, compiled and run on any computer or phone without installing anything.

How it works

  1. The compiler is downloaded once. The first time you press Run, the browser fetches a real C compiler (about 29 MB) and keeps it, so later runs start at once, even offline.
  2. Your program is compiled on your device. The compiler turns your C code into WebAssembly, a compact machine code that every modern browser can run safely.
  3. The program runs in a sandbox. It gets its own private folder for files and cannot touch anything else on your computer. Nothing is uploaded to a server.

What is inside

Clang
The C compiler. It reads your program, checks it, reports errors and warnings, and translates it into machine code. Clang is part of the LLVM project and is the same compiler used by Apple's Xcode, Android, Chrome and many universities; C Lab uses version 22.
LLVM and LLD
LLVM is the toolkit behind Clang that optimises the program (the O0, O1 and O2 settings choose how hard it tries). LLD is the linker, which joins your program with the C library into one runnable file.
WebAssembly
A standard form of machine code built into every modern browser. Clang and LLD have themselves been compiled to WebAssembly, which is how a full compiler can run inside a web page. Your program is compiled to WebAssembly too.
WASI and wasi-libc
WASI is a standard way for a WebAssembly program to use files, read input and print output. wasi-libc is the C standard library built on it, providing printf, scanf, fopen, malloc, math.h and the rest.
Web Worker
The compiler and your program run in a background thread, so the page stays responsive and the Stop button can end a program that never finishes.
CodeMirror
The editor, which provides syntax colouring, line numbers, bracket matching, search and replace, and the error underlines.

Compared with a desktop compiler

The C language and library are the same as with GCC in Dev-C++ or Code::Blocks, so a correct program gives the same results. Programs run somewhat slower than a native program, which does not matter for practical classes. The main difference is that input is typed in advance rather than while the program runs; see Help.

Credits and licences

The compiler package is @live-codes/clang-wasm (MIT), built on LLVM (Apache 2.0 with the LLVM exception) and wasi-libc. The editor is CodeMirror (MIT) and the typeface is Libertinus Serif (SIL Open Font Licence). Full notices are in the notices file. C Lab itself is open source under the MIT licence: github.com/mcodexvb/compilec.