|
|
Log in / Subscribe / Register

Perl-preprocessed C in the 21st Century

Perl-preprocessed C in the 21st Century

Posted Jan 15, 2026 14:37 UTC (Thu) by paulj (subscriber, #341)
In reply to: Perl-preprocessed C in the 21st Century by kleptog
Parent article: The State of OpenSSL for pyca/cryptography

Well... you actually can do keyword arguments in C reasonably easily and well (for a reasonable number of arguments), with no need to resort to expensive key-val that require runtime lookups of key objects. Just use a struct for keyword arguments, and create an anonymous struct at the caller to pass in the keyword args via the struct - unspecified kw args will be the type's default (e.g. 0 or NULL).

#include <stdio.h>

struct bar_args {
int x;
int y;
};

int bar(int z, struct bar_args args) {
return z * args.x + args.y;
}

int main (const int argc, const char *argv[]) {
printf("1 2 (0) %u\n", bar (2, (struct bar_args) { .x = 2}));
printf("1 2 3 %u\n", bar (2, (struct bar_args) { .x = 2, .y = 3}));
return 0;
}


to post comments


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds