9fans / plan9port

Plan 9 from User Space
https://9fans.github.io/plan9port/
Other
1.62k stars 320 forks source link

Compiler throws a warning for u.h sizeof #519

Closed camsn0w closed 2 years ago

camsn0w commented 3 years ago

/home/sn0w/plan9port/include/u.h:65:42: warning: expression does not compute the number of elements in this array; element type is ‘struct __jmp_buf_tag’, not ‘long int’ [-Wsizeof-array-div] 65 | typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)]; | ^ /home/sn0w/plan9port/include/u.h:65:42: note: add parentheses around the second ‘sizeof’ to silence this warning

bhuntsman commented 2 years ago

Can you include the compiler error in the issue?

Thank you!

benghancock commented 2 years ago

I ran into the same issue, so figured I'd chime in on this thread even though it's been open for a while. First things first though: Thanks very much for plan9port! I came to know the joys of using Acme thanks to this project.

I ran the INSTALL script on a machine running openSUSE the other day and saw a stream of repeated compiler warnings, the most common of which was this one, excerpted with context:

>>> cd /usr/local/plan9/src/cmd/devdraw; mk -k install
9c -I/usr/include x11-load.c
/usr/local/plan9/include/u.h:65:42: warning: expression does not compute the number of elements in this array; element type is ‘struct __jmp_buf_tag’, not ‘long int’ [-Wsizeof-array-div]
   65 | typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)];
      |                                          ^
/usr/local/plan9/include/u.h:65:42: note: add parentheses around the second ‘sizeof’ to silence this warning

My knowledge of C is very shallow, but following the message in the warning, I tried making this change (which I see is already a PR in #520)

diff --git a/include/u.h b/include/u.h
index 856e10f4..3d779483 100644
--- a/include/u.h
+++ b/include/u.h
@@ -62,7 +62,7 @@ extern "C" {
 #define _NEEDUINT 1
 #define _NEEDULONG 1

-typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)];
+typedef long p9jmp_buf[sizeof(sigjmp_buf)/(sizeof(long))];

 #if defined(__linux__)
 #      include <sys/types.h>

Re-executing ./INSTALL afterward successfully silences this warning, and things still seem to work fine (though I admittedly only tested Acme).

Here's the version of gcc I was running:

gcc version 11.2.1 20211124 [revision 7510c23c1ec53aa4a62705f0384079661342ff7b] (SUSE Linux)

OS information

$ lsb_release -a
LSB Version:    n/a
Distributor ID: openSUSE
Description:    openSUSE Tumbleweed
Release:        20211223
Codename:       n/a

Acme also worked without the change, and I'm not sure if the change would have other effects elsewhere, but I thought I would share this info in case it's helpful.

Thanks again!