Few lesser known tricks, quirks and features of C

This page summarizes the projects mentioned and recommended in the original post on news.ycombinator.com

Our great sponsors
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • SaaSHub - Software Alternatives and Reviews
  • libwheel

    Generic data structures for the C programming language with (near) zero overhead.

  • > 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.

  • printbf

    Brainfuck interpreter inside printf

  • 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

  • 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.

    InfluxDB logo
  • printf-tac-toe

    tic-tac-toe in a single call to printf

  • 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

  • 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.

  • 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...

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts