Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SECP256K1_SCHNORRSIG_EXTRAPARAMS_INIT does not work with C++ #962

Closed
guidovranken opened this issue Jul 3, 2021 · 1 comment · Fixed by #963
Closed

SECP256K1_SCHNORRSIG_EXTRAPARAMS_INIT does not work with C++ #962

guidovranken opened this issue Jul 3, 2021 · 1 comment · Fixed by #963

Comments

@guidovranken
Copy link

#include <secp256k1.h>
#include <secp256k1_schnorrsig.h>

int main(void)
{
    secp256k1_schnorrsig_extraparams extraparams = SECP256K1_SCHNORRSIG_EXTRAPARAMS_INIT;
    return 0;
}

This compiles as C but not as C++.

clang++:

x.cpp:6:52: error: initializer-string for char array is too long
    secp256k1_schnorrsig_extraparams extraparams = SECP256K1_SCHNORRSIG_EXTRAPARAMS_INIT;
                                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/secp256k1/include/secp256k1_schnorrsig.h:90:5: note: expanded from macro 'SECP256K1_SCHNORRSIG_EXTRAPARAMS_INIT'
    SECP256K1_SCHNORRSIG_EXTRAPARAMS_MAGIC,\
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/secp256k1/include/secp256k1_schnorrsig.h:88:48: note: expanded from macro 'SECP256K1_SCHNORRSIG_EXTRAPARAMS_MAGIC'
#define SECP256K1_SCHNORRSIG_EXTRAPARAMS_MAGIC "\xda\x6f\xb3\x8c"
                                               ^~~~~~~~~~~~~~~~~~
1 error generated.

g++

In file included from x.cpp:2:0:
x.cpp: In function ‘int main()’:
/secp256k1/include/secp256k1_schnorrsig.h:93:1: error: initializer-string for array of chars is too long [-fpermissive]
 }
 ^
x.cpp:6:52: note: in expansion of macro ‘SECP256K1_SCHNORRSIG_EXTRAPARAMS_INIT’
     secp256k1_schnorrsig_extraparams extraparams = SECP256K1_SCHNORRSIG_EXTRAPARAMS_INIT;
@real-or-random
Copy link
Contributor

I guess there's an unwritten rule that the include files should work in C++ too... Maybe we should test this in CI.

Here's a related CI failure after merging the same PR #844 (when CI was running on the PR, we didn't have -Werror yet...), which doesn't deserve an issue on its own:
https://github.com/bitcoin-core/secp256k1/runs/2978402299

cc @jonasnick

real-or-random added a commit to real-or-random/secp256k1 that referenced this issue Jul 4, 2021
unsigned char foo[4] = "abcd" is not valid C++ because the string
literal "abcd" does not fit into foo due to the terminating NUL
character. This is valid in C, it will just omit the NUL character.

Fixes bitcoin-core#962.
dderjoel pushed a commit to dderjoel/secp256k1 that referenced this issue May 23, 2023
unsigned char foo[4] = "abcd" is not valid C++ because the string
literal "abcd" does not fit into foo due to the terminating NUL
character. This is valid in C, it will just omit the NUL character.

Fixes bitcoin-core#962.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants