Hacker News new | ask | show | jobs
by foota 338 days ago
Funny enough I recently wrote my own hack using this linker feature in C, to implement an array of static counter definitions that can be declared anywhere and then written out (e.g., to prometheus) in one place.

Note that as I later found out, this doesn't work with Mac OS's linker, so you need to use some separate incantations for Mac OS.

1 comments

I wrote a portable abstraction for this that works across Linux, MacOS, and Windows: https://github.com/protocolbuffers/protobuf/blob/4917ec250d3...

I call them "linker arrays". They are great when you need to globally register a set of things and the order between them isn't significant.