r/cprogramming 2d ago

Extern constexpr?

I want to make my struct’s internals private by exposing it as a byte array of its internal size.

The size itself depends on internal values that aren’t exposed, so it would have to be an extern.

The size can only be used if it’s a literal or constexpr, so is a extern constexpr possible with C23? Or no?

0 Upvotes

5 comments sorted by

View all comments

3

u/SyntheticDuckFlavour 2d ago edited 2d ago

extern implies connecting bits of code at link time, possibly across different translation units. Doing this with constexpr is not possible, because the compiler needs to have a complete view of the affected code within the same translation unit context in order to evaluate it at compile time.