Generator names should be passed as const char* and not as char*. #30
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Functions like unif01_CreateExternGen01 have currently a prototype of
unif01_Gen *unif01_CreateExternGen01 (char *name, double (*f_U01)(void))
i.e. they are alloed to change the string pointed to by name. This is not expected, and these functions actually DO NOT change the contents of name. Therefore, name should be const qualified:
unif01_Gen *unif01_CreateExternGen01 (const char *name, double (*f_U01)(void))
As a simple test case, consider
unsigned myrand (void)
{
static unsigned u;
return ++u;
}
const char myrand_name[] = "myrand";
unif01_Gen *gen_myrand (void)
{
return unif01_CreateExternGenBits (myrand_name, myrand);
}
testu01.c: In function 'gen_myrand':
testu01.c:13:40: warning: passing argument 1 of 'unif01_CreateExternGenBits' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
13 | return unif01_CreateExternGenBits (myrand_name, myrand);
| ^~~~~~~~~~~
In file included from testu01.c:1:
$prefix/include/unif01.h:147:47: note: expected 'char *' but argument is of type 'const char *'
147 | unif01_Gen *unif01_CreateExternGenBits (char *name,
| ~~~~~~^~~~