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:

Jealousy In Polyamory Isn't A Big Problem And I'm Tired Of Being Gaslit By Big Self-Help

The nuance is in the post, guys

via Thing of Things July 18, 2024

Trust as a bottleneck to growing teams quickly

non-trust is reasonable • trust lets collaboration scale • symptoms of trust deficit • how to proactively build trust

via benkuhn.net July 13, 2024

Coaching kids as they learn to climb

Helping kids learn to climb things that are at the edge of their ability The post Coaching kids as they learn to climb appeared first on Otherwise.

via Otherwise July 10, 2024

more     (via openring)