
typedef enum { THING_INVALID = -1, #define THING(X) THING_ ## X, //#include "thingdefs.h" // start of thingdefs.h #ifndef THING #error "Missing function-like macro definition" #endif THING(apple) THING(banana) THING(orange) #undef THING // end of thingdefs.h } thing_t; static const char *const dict[] = { #define THING(X) #X, //#include "thingdefs.h" // start of thingdefs.h #ifndef THING #error "Missing function-like macro definition" #endif THING(apple) THING(banana) THING(orange) #undef THING // end of thingdefs.h }; static int compare_strings(const void *const key, const void *const elemp) { assert(key); assert(elemp); const char *const *const stringp = elemp; return strcmp(key, *stringp); } thing_t string_to_id(const char *const key) { char const *prev = ""; for (size_t i = 0; i < _Countof dict; ++i) { char const *const elem = dict[i]; assert(strcmp(prev, elem) < 0); prev = elem; } (void)prev; const char *const *const elemp = bsearch(key, dict, _Countof dict, sizeof dict[0], compare_strings); if (elemp) { return (thing_t)(elemp - dict); } else { return THING_INVALID; } } int main(const int argc, const char *const argv[const static argc + 1]) { for (size_t i = 0; i < argc; ++i) { thing_t const t = string_to_id(argv[i]); switch (t) { case THING_apple: puts("Crunch!"); break; case THING_banana: puts("Squish!"); break; case THING_orange: puts("Splatter!"); break; case THING_INVALID: fputs("Invalid argument", stderr); break; } } return 0; }
I think I need help. I just read "USB-C" as being a new version of the C programming language, and when we've already got K&R, ANSI, C99 and so on the last thing we need is another C standard!
I rewrote my #buddhabrot renderer in #cprogramminglanguage using #openmp! It runs faster than my #cplusplus `std::threads` implementation.
Vývoj jazyka C - text Dennise Ritchieho o počátcích C v rocích 1969-73
#c #Cprogramminglanguage #programming #DennisRitchie #KenThompson #unix #history #computers #paper #translation #preklad #historie #jazykC #retropocitace
Programovací jazyk C byl vytvořen na počátku 70. let 20. století jako jazyk pro implementaci systému pro vznikající operační systém Unix. Byl odvozen z beztypového jazyka BCPL a vyvinul typovou strukturu; vytvořen na malém stroji jako nástroj pro zlepšení skromného programovacího prostředí se stal jedním z dominantních jazyků současnosti. Tento článek se zabývá jeho vývojem.
If I'm understanding things correctly this person wrote a UI library from the ground up, with C. With lots of documentation. How cool! https://nakst.gitlab.io/tutorial/ui-part-1.html