Currently all of the structs in the public API are only typedef’d, rather than both named and typedef’d. As such, the structs cannot be forward declared and instead using the struct name (typedef) in a header requires including the library headers. This can be problematic for projects which want to reduce the inclusion tree as much as possible.
For some context behind this request, in my MuSig2 PR to Bitcoin Core, since the secp256k1_musig_secnonce
cannot be copied or serialized, I have to pass around a pointer to the object in various functions, so many headers need to include secp256k1_musig.h
just for the struct’s declaration. Including secp256k1_musig.h
in those headers result in needing to directly link libsecp256k1 in several of build targets that did not previously require it. This issue seems like it can be avoided by forward declaring that (and other) struct, but in order to do so, it needs to be named in the libsecp headers.
My current workaround is to pass void *
and then cast them as necessary but I don’t really like doing that.