Logarithmic-time string-to-enum lookup using only standard C library functions: https://godbolt.org/z/6aaxehzf5
#cprogramminglanguage #clanguage
Compiler Explorer - C

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; }

Fun with array and function decay.
#cprogramming #cprogramminglanguage

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!

#C #CLanguage #CProgrammingLanguage

wow don't i just love #CProgramming wow it's so nice to program in #CProgrammingLanguage i love #raylib and i love error handling in C and #segmentationfault and i should probably install gdb or something

I rewrote my #buddhabrot renderer in #cprogramminglanguage using #openmp! It runs faster than my #cplusplus `std::threads` implementation.

https://github.com/Zi7ar21/buddhabrot

@openmp_arb

GitHub - Zi7ar21/buddhabrot: A simple Buddhabrot renderer written in C++11.

A simple Buddhabrot renderer written in C++11. Contribute to Zi7ar21/buddhabrot development by creating an account on GitHub.

GitHub
Fil-C

Vývoj jazyka C

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

#CProgrammingLanguage #UserInterfaces

UI tutorial part 1

Hello World C Code - Light Syntax Scheme Programmer Design

➡️ https://geeksta.net/design/helloworld.c-perldoc/

This design for coders, developers, programmers, hackers or how you might call it, shows "Hello, World!" in C code with a syntax highlighting scheme that is used in editors for coding.

#CCode #ComputerCode #ComputerProgrammer #CProgrammer #CProgramming #CProgrammingLanguage #GeekHumor #GeekMerch #HelloWorld #ProgrammerHumor #ProgrammerMerch #ProgrammingLanguage #SoftwareDeveloper #ComputerScience

Hello World C Code - Light Syntax Scheme Programmer Design | Geeksta

The Hello World program is frequently used in programming books and is often the first program computer programmers try when learning a new programming language. Ever happened to you? This...