Run little bits of C from your shell and see the result immediately. You type C statements or a single expression (what goes inside main()), crun wraps it into a minimal program, compiles with TinyCC, runs it, and auto‑prints a result when you don’t explicitly print.
- Auto‑prints the last expression or the last declared/assigned variable
- Knows basic int vs float printing (uses
%lldfor ints,%gfor floats) math.hready (e.g.,sin,sqrt)- Interactive multiline input and editor mode
- No build artifacts (uses a temp file and cleans up)
- PowerShell 7+ (pwsh). It can also work on Windows PowerShell, but is developed against pwsh.
- Tiny C Compiler (tcc) on your PATH. Download TinyCC and ensure
tcc.exeis available in your PATH.- Windows: download from the TinyCC site (or your preferred package manager) and add the install folder to PATH.
- Put
crun.ps1somewhere convenient (or clone this repo). - Optionally add a shell alias so you can just type
crunanywhere:
# In your $PROFILE
Set-Alias crun (Resolve-Path 'C:\\path\\to\\crun.ps1')Alternatively, call it explicitly when testing:
pwsh -NoProfile -File .\crun.ps1 1+2Use single quotes around your C snippet. This avoids PowerShell interpreting parentheses and quotes.
# Integers and operators
crun 100%27 # 19
crun 1+2 # 3
crun 1<<5 # 32
# Floating point & math.h
crun 'sqrt(2)' # 1.41421
crun 'sin(0.5)' # 0.479426
# Explicit printing
crun 'printf("hi!\n")' # hi!
# Variables — last variable auto‑prints
crun 'int a=7,b=27; int k=b%a' # 6
crun 'double x=2.5; x' # 2.5If you insist on double quotes, you must escape/double the inner quotes because PowerShell parses them:
# Either escape with the PowerShell double-double-quote escape
crun "printf(""hi!\n"")"
# Or single outside and double inside
crun 'printf("hi!\n")'See EXAMPLES.md for a grab‑bag of ready‑to‑run snippets.
- No arguments: interactive multiline input. Type lines; finish with
EOFon its own line. -UseEditor: opens your editor to write multiple lines; save & close to run. The script checks$env:VISUAL,$env:EDITOR, then triesvim,nvim,nano,code -w,notepad.
Interactive example:
crun
Enter C statements for inside main(); finish with EOF on its own line.
Examples:
printf(\ hi\\n\);
int a=7,b=27; int k=b%a;
sin(0.5) // (no printf) last expr auto-prints
c>: int s=0;
c>: for(int i=1;i<=5;i++) s+=i;
c>: s
c>: EOF
15Editor mode:
crun -UseEditor
# Write statements inside main(), for example:
# int s=0; for(int i=0;i<10;i++) s+=i; s
# Save & exit to run- If you don’t call
printf/putsand don’treturn,crunauto‑prints:- The last expression, or
- The last declared/assigned variable’s value (tries to pick int vs float formatting)
- If you do print or explicitly
return, auto‑print is skipped. You’re in full control. - A trailing semicolon is added for you if you forget it.
Headers included by default: stdio.h, stdlib.h, stdint.h, stdbool.h, string.h, math.h, time.h, errno.h, assert.h, plus a convenience macro #define BIT(x) (1ULL<<(x)).
PowerShell is not a dumb pass‑through; it parses parentheses, quotes, and % (alias for ForEach-Object).
- Prefer single quotes around the entire snippet:
crun 'printf("hi!\n")' - Unquoted snippets that contain parentheses may be split by PowerShell. Example:
crun sqrt(2)is parsed into two tokens (sqrtand2), producing a compile error. Quote it:crun 'sqrt(2)'. - If you use double quotes, escape inner quotes with double doublequotes:
crun "printf("\""hi!\n"")". - Escaping using a backslash (e.g.,
crun "printf(\"hi!\n\")") does not work.
See LICENSE.