Our great sponsors
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
-
color-flood-for-amstrad-cpc
A puzzle game for 2 to 4 player. Written in portable C as an experiment: can a program with non-trivial algorithmic logic be compiled and run on an 8-bit platform? Answer: yes.
> C11 added _Generic to language, but turns out metaprogramming by inhumanely abusing the preporcessor is possible even in pure C99: meet Metalang99 library.
I'm actually working on a library doing just that! It's still in very (very) early development, but maybe someone may find it to be interesting. [GitHub](https://github.com/jenspots/libwheel).
[Here](https://github.com/jenspots/libwheel/blob/main/include/wheel... the implementation of a vector. [Here](https://github.com/jenspots/libwheel/blob/main/tests/impl/st...) is a test file implementing a vector of strings.
Somewhat related to this, printf alone in a loop is Turing-complete, by using %-directives like that. It was introduced in “Control-Flow Bending: On the Effectiveness of Control-Flow Integrity” (Carlini, et al. 2015) and the authors have implemented Brainfuck and an obfuscated tic-tac-toe with it.
[0]: https://nebelwelt.net/publications/files/15SEC.pdf
[1]: https://github.com/HexHive/printbf
[2]: https://github.com/carlini/printf-tac-toe
Somewhat related to this, printf alone in a loop is Turing-complete, by using %-directives like that. It was introduced in “Control-Flow Bending: On the Effectiveness of Control-Flow Integrity” (Carlini, et al. 2015) and the authors have implemented Brainfuck and an obfuscated tic-tac-toe with it.
[0]: https://nebelwelt.net/publications/files/15SEC.pdf
[1]: https://github.com/HexHive/printbf
[2]: https://github.com/carlini/printf-tac-toe
const int myarray[mysize];
* Good news: C can do compile time constant structs and array with deep self-references.
Yes, in C you can define and fully declare complex data structures that are accepted as compile-time constants, including pointers to parts of itself.
See "self-contained, statically allocated, totally const data structure with backward and forward references (pointers)?" for a previous example at https://stackoverflow.com/questions/47037701/can-c-syntax-de...
-----------------
I used this for a game on a retro machine where such a data structure avoids code which would have been several times (perhaps 10 times) bigger: https://github.com/cpcitor/color-flood-for-amstrad-cpc/blob/...
Here's another take showing two variant: where overall construct is an array then a struct: https://gist.github.com/fidergo-stephane-gourichon/792c194e1...