Open randygalbraith opened 6 years ago
I don't really understand why I shouldn't be allowed to name parameters index
. Can you provide the error message and the diagnostic flags that you used to compile cJSON?
Hi FSMaxB,
Sure. Here is the output:
gcc -c -fPIC -std=c89 -pedantic -Wall -Werror -Wstrict-prototypes -Wwrite-strings -Wshadow -Winit-self -Wcast-align -Wformat=2 -Wmissing-prototypes -Wstrict-overflow=2 -Wcast-qual -Wc++-compat -Wundef -Wswitch-default -Wconversion -O3 -pipe -std=gnu99 -fstack-protector cJSON.c cc1: warnings being treated as errors cJSON.c: In function 'get_array_item': cJSON.c:1743: error: declaration of 'index' shadows a global declaration /usr/include/string.h:489: error: shadowed declaration is here cJSON.c: In function 'cJSON_GetArrayItem': cJSON.c:1762: error: declaration of 'index' shadows a global declaration /usr/include/string.h:489: error: shadowed declaration is here make[1]: *** [Makefile:80: cJSON.o] Error 1
Please keep in mind this run of make and gcc is from within our internal package maintenance system. I suspect a run of make from the command line would not run into this issue.
Cheers, -Randy
man 3 index:
index, rindex - locate character in string
#include <strings.h>
char *index(const char *s, int c);
CONFORMING TO 4.3BSD; marked as LEGACY in POSIX.1-2001.
So this warning will occur whenever you include strings.h before cJSON.h.
Of course, this is perfectly correct C code with no risk at all, since these functions don't use the deprecated index()
function. Combining -Werror
with warnings not included in -Wall
and -Wextra
(like the -Wshadow
that triggers this) is not a good idea.
Sorry for taking so long to get back to this.
So if I understand this correctly, the index
function comes from an outdated POSIX extension?
Then there maybe should a way for me to disable it by setting or unsetting a define. I'll look into that.
@randygalbraith Can you check if the disable-nonstandard
-Branch fixes this issue?
While compiling cJSON on Red Hat GNU/Linux 6 gcc reported a name conflict error. This happened only with enhanced gcc flags for diagnostics we typically use to compile packages. For what it is worth here is the patch that I applied to resolve the issue (see below). Thank you to all the contributors of cJSON. Our lead engineer who is using it has found it very nice.
Cheers, -Randy