RSSAmplifier

Blog

DavidsBlog

David's Blog

davidpriver.comRSS feed ↗10 posts

Latest posts

Fixing C's Biggest Mistake

Fixing C's Biggest Mistake Home Fixing C's Biggest Mistake David Priver , June 14th, 2026 Back in 2009, Walter Bright (creator of the D programming language and Digital Mars C++ compiler before that), wrote an article arguing that C's biggest mistake was "Conflating pointers with arrays." In particular, that it is impossible to pass an array to a function without it being converted to a pointer,…

adding-reflection-to-C

Adding reflection to C Home Adding reflection to C David Priver , May 27th, 2026 Reflection in programming is the ability for a program to introspect its own datastructures and procedures, either at compile time or at run time. This is a key building block of metaprogramming. This is frequently used for automatically generating serialization and deserialization code, in-app debuggers and structure…

VIM Macros are Overrated

VIM Macros are Overrated Home VIM Macros are Overrated David Priver , Nov 29th, 2024 Macros I'm a big VIM user and enjoy working in it, both professionally and recreationally. One of vim's nice features is the ability to record macros into a register and then replay it. As the macros can include motion, you can set them up so that they can be easily repeated and use a count modifier, like 22@w to…

C-macro-reflection-in-D

C-macro-reflection-in-D Home C-macro-reflection-in-D David Priver , July 30th, 2024 I was reading Hacker News when I saw the link to this article . I've been playing around with D lately and thought to myself "I bet D could do this as well". D added the ability to import C files (with macros ) and has strong reflection capabilities as well. So here is my attempt at that: With a C file with macros:…

c-hash-table

Hashtable in C Home Hashtable in C David Priver , Jan 3rd, 2024 Contents Basic Reqirements Design Decisions Data Layout Implementation Deletion Alterations Conclusion Copyright There's many times when the problem you are solving needs something like a map of keys to values with O(1) insertion and retrieval. C doesn't come with one already ready-for-use like more "modern" languages like Python, so…

C in WASM

C in WASM Home C in WASM David Priver , January 20th, 2023 Contents The Compiler The Flags The Standard Library malloc Strings Building the Code Instantiating the Code Debugging Profiling Demo Copyright If you search for information on how to compile C code to webassembly, most sources will tell you to use Emscripten. For various reasons (complication, bloat, etc.), you probably don’t want to use…

Doctests in C

Doctests in C Home Copyright Doctests in C David Priver , July 30th, 2022 Doctests are a technique of testing the examples embedded in documentation. They were first created for the Python language in 1999, but have since spread to other languages like Rust. Embedding examples in documentation is very useful as it can immediately clarify usage of an API or the meaning of unclear terms. However,…

_Generic for Type Reification in C

_Generic for Type Reification in C Home _Generic _Generic for Tagging Use Cases Conclusion Appendix: Other Languages Copyright _Generic for Type Reification in C David Priver , July 29th, 2022 Occasionally, you need to turn a type into a value. An example of when you would need to do this is when constructing a tagged union that can hold pointers to different types: // anypointer.h # include…

run(**vars(args))

run(**vars(args)) Home run(**vars(args)) Copyright run(**vars(args)) David Priver , July 27th, 2022 Python has the pretty decent argument parsing module argparse as part of the standard library. It offers a procedural API for building up a parser for a program's command line arguments. After calling parse_args , you get back a simple namespace object that contains the values as defined by your…

Templates in C

Templates in C Home Generics in C Void Pointers Function pointers Inline Macros Code Generating Macros Source Code Generation Copy Paste Template Headers with Multiple Inclusion Template Headers Example Usage Conclusion Copyright Templates in C David Priver , July 22nd, 2022 Sometimes I see people on the internet sharing their generic libraries in C. More often than not, they turn out to use some…