Warning compiling pikchr on Windows 10
(1) By Doug (doug9forester) on 2020-11-27 21:19:43 [link] [source]
I got the following warnings when compiling pikchr on Windows 10 under Cygwin:
$ make all
./lemon pikchr.y
cat pikchr.h.in >pikchr.h
gcc -O0 -g -Wall -Wextra -DPIKCHR_SHELL pikchr.c -o pikchr -lm
In file included from pikchr.c:122:
pikchr.y: In function ‘pik_parse_macro_args’:
pikchr.y:4910:36: warning: array subscript has type ‘char’ [-Wchar-subscripts]
4910 | while( t->n>0 && isspace(t->z[0]) ){ t->n--; t->z++; }
| ~~~~^~~
pikchr.y:4911:36: warning: array subscript has type ‘char’ [-Wchar-subscripts]
4911 | while( t->n>0 && isspace(t->z[t->n-1]) ){ t->n--; }
| ~~~~^~~~~~~~
PS. I would nice to be able to clone the source code instead of copying each file individually. Any chance of making the source available on github?
(2) By Stephan Beal (stephan) on 2020-11-27 21:31:57 in reply to 1 [link] [source]
Any chance of making the source available on github?
That question (from you) was answered over in /forumpost/d4a1db5dcf.
(3) By Doug (doug9forester) on 2020-12-01 00:18:46 in reply to 2 [link] [source]
Stephen, Do you maintain pikchr or is it Richard's baby? Can you answer my question about the compiler warnings?
(4) By Doug (doug9forester) on 2020-12-04 16:33:01 in reply to 1 [link] [source]
Richard, I posted these warnings a week ago and nobody has stepped up to answer whether they are a problem or not. I really don't like char/wchar warning messages.
(5) By drh on 2020-12-04 17:19:29 in reply to 4 [link] [source]
I don't have the time to go chasing Cygwin warnings right now. Note that none of the compilers I normally use have issues with using a character as an index into an array. (Why should they?) If you have a patch, I will be happy to consider it. But otherwise this is not worth pursuing.
(6.1) By Warren Young (wyoung) on 2020-12-04 19:50:48 edited from 6.0 in reply to 5 [link] [source]
the compilers I normally use have issues with using a character as an index into an array. (Why should they?)
Because array indices often go beyond 127, char is often signed, and the compiler can't see that in this particular instance that "n" cannot be greater than 9.
However, there's something bogus about those warnings: how does it deduce "char" as the type of 0 in the first warning? Shouldn't it be "int"? Furthermore, PToken.n
is unsigned int in the second warning, not char, so what's it babbling about?
What version of GCC is this? Maybe we can reproduce it on another platform, which we do have access to. (I'd have to dual-boot into Windows to replicate your Cygwin issue, else I'd have tackled this warning earlier, Doug.)
(7.1) Originally by Doug (doug9forester) with edits by drh on 2020-12-04 20:45:07 from 7.0 in reply to 6.1 [link] [source]
$ gcc --version gcc (GCC) 10.2.0
(8) By Warren Young (wyoung) on 2020-12-04 21:39:29 in reply to 7.1 [source]
GCC 10.2.0 on macOS 10.15.7 doesn't do that:
Index: Makefile
==================================================================
--- Makefile
+++ Makefile
@@ -1,7 +1,9 @@
-CC = gcc
-CFLAGS = -O0 -g -Wall -Wextra
+CC = gcc-10
+CFLAGS = -O0 -g -Wall -Wextra \
+ -I/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include \
+ -L/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/lib
LIBS = -lm
all: pikchr
pikchr: pikchr.c
No warnings or errors.