FakeC
brainfuck that a C compiler runs as it is.
None1, 2023 · Turing complete: yes · ●○○ easy · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
None1 made FakeC in 2023. Every brainfuck command is replaced by one line of C, and the program is wrapped in a main with a tape of 1,000,000 chars. So a FakeC program is also a C program, and the specification suggests compiling it with GCC and -O2 to get a brainfuck program that runs fast.
Read the story
Because it is C, the end of the input works as in C. getchar gives EOF, which is -1, and a char keeps that as 255. The cat therefore does not stop at the end of its input. It stops at a 0 byte.
The machine
| brainfuck | FakeC |
|---|---|
| start | #include<stdio.h> char tape[1000000]; int p; int main(){ |
+ - | ++tape[p]; --tape[p]; |
> < | ++p; --p; |
, . | tape[p]=getchar(); putchar(tape[p]); |
[ ] | while(tape[p]){ } |
| end | return 0; } |
The specification's table leaves the brace off while(tape[p]), but both of its examples have it, and so does this implementation. Spaces and line breaks are passed over, so a command may share a line. Cells wrap as bytes, and a cell outside the tape is an error.
Example
Eight times eight plus one is 65, an A.
Eight times eight plus one is 65, an A.
One character in and out.
The Hello World has 106 command lines, the usual brainfuck one turned line by line, and it prints Hello World! and a line feed.
Patterns it teaches
- Polyglot: every program is valid FakeC and valid C.
- Camouflage: brainfuck dressed as C.
- Turing completeness: it is brainfuck with other spelling.
Further
See also
FakeC builds on Brainfuck.
Esoteric subset
Brainfuck equivalents
Write your own in Run Convert a program from FakeC
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: fakec.
Command line
shib run fakec -e '#include<stdio.h>
char tape[1000000];
int p;
int main(){
tape[p]=getchar();
while(tape[p]){
putchar(tape[p]);
tape[p]=getchar();
}
return 0;
}' --input 'FakeC '