简体   繁体   中英

Why can't I use `BIGNUM` in this C struct declaration?

I was experimenting with some ~2005 C code (using OpenSSL 0.9.8, I think) and I tried make -ing it with OpenSSL 3.0.2 on Ubuntu 22.04.

Minimum example:

#include <openssl/bn.h>

struct fraction
{
    BIGNUM numerator;
    BIGNUM denominator;
}

Expected: everything builds, just as intended.

Actual: complier complains about incomplete type declaration for both fields.

Why does this happen? Is this not a valid declaration? Or is it something else?

Later versions of OpenSSL made several types opaque, including BIGNUM , which means you can't instantiate them directly in user code. The BIGNUM type in particular became an opaque type starting with version 1.1.0.

You would instead need to use pointers:

struct fraction
{
    BIGNUM *numerator;
    BIGNUM *denominator;
};

And use the appropriate functions to create and destroy them, as well as use the relevant accessor functions to access the members.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM