Hacker News new | ask | show | jobs
by teraflop 1370 days ago
Ah, I missed that, but I don't think your comment is precisely correct either.

All of the function definitions are declared with OLIVECDEF, which by default is #defined as `static inline`. So if you want to only get a single copy of the implementation, you would have to choose one compilation unit that defines OLIVEC_IMPLEMENTATION, and you would have to define OLIVECDEF as something else (like the empty string) that causes the functions to be non-static.

Still kind of hacky, but not as bad as I thought.

EDIT: I just noticed that only some of the functions are marked with OLIVECDEF, so you have to do this trick if you want to reference the library in multiple compilation units, or else you would get duplicate symbols. The default behavior doesn't seem like it would ever be useful.

1 comments

All good - I struggled when I first started with C.

The macro preprocessor is like a Schrodinger's Cat of helpful and painful!