Implicitly Typed C

December 11th, 2023
tech
I don't know any good reason to do this, but if you would rather be writing Python or JavaScript here's something you can do with a C compiler:

$ cat tmp.c
foo(x) {
  return x+5;
}
bar() {
  return 4;
}
main() {
  printf("%d\n", foo(bar()));
}

$ gcc -w -o tmp.out tmp.c && ./tmp.out
9

This code takes advantage of a historical quirk of C where types are assumed to be int unless otherwise specified: foo(x) {...} is equivalent to int foo(int x) {...}. Additionally the printf works because gcc includes stdio.h by default, and main is special-cased to assume a final return 0.

I've occasionally used this style when writing example code to remove visual noise, but it's probably not a good idea there either.

Comment via: facebook, lesswrong, mastodon

Recent posts on blogs I like:

Starting With Chords

A lot of people play fiddle. Basically nobody starts by learning chords before learning melodies. But that's actually how I learned. I started with chords. One of the nice things about learning to play violin this way is that you can go busking even…

via Anna Wise's Blog Posts November 15, 2024

Stuffies

I have some stuffies and I just have a bunny. Bunny is a rabbit. Woof is a seal. My favorite stuffie is bun bun. I play with my stuffies. Sometimes I jump up with them and I roll them. I can just throw them in the air when I want to play bthululubp wi…

via Nora Wise's Blog Posts November 15, 2024

You Can Buy A Malaria Net

2024 election takes

via Thing of Things November 6, 2024

more     (via openring)