Compiler Warnings
SteveFosdick opened this issue · 2 comments
Thanks for A09. When compiling on Linux with gcc 9.1.0 I get some warnings, of which the first looks to be of some concern:
a09.c:2361:38: warning: division ‘sizeof (struct regrecord *) / sizeof (struct regrecord)’ does not compute the number of array elements [-Wsizeof-pointer-div]
2361 | for (i = 0; i < (sizeof(bitregtable) / sizeof(bitregtable[0])); i++)
| ^
a09.c:1658:19: note: first ‘sizeof’ operand was declared here
1658 | struct regrecord *bitregtable = bitregtable09;
| ^~~~~~~~~~~
a09.c: In function ‘expandmacro’:
a09.c:6055:5: warning: unused variable ‘nMacLine’ [-Wunused-variable]
6055 | int nMacLine = 1; /* current macro line */
| ^~~~~~~~
a09.c: In function ‘pseudoop’:
a09.c:5956:5: warning: ‘strncpy’ output may be truncated copying 8 bytes from a string of length 32 [-Wstringop-truncation]
5956 | strncpy(modulename, namebuf, 8);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You are right regarding the first warning - that's bad, and I wonder why it hasn't been flagged by my compiler (Microsoft C++ 12 / Visual Studio 2008). It should have been.
Obviously, this one crept in when I added the 6800 support.
I'll upload a fix as soon as I can find the time. Maybe tonight, but I wouldn't count on it.
If you need it now, the remedy is simple; add a line
int bitregtablesize = sizeof(bitregtable09) / sizeof(bitregtable09[0]);
after the declaration of bitregtable, then replace
for (i = 0; i < (sizeof(bitregtable) / sizeof(bitregtable[0])); i++)
with
for (i = 0; i < bitregtablesize; i++)
... that's it. A complete implementation (which I'll upload) would also set bitregtablesize each time the bitregtable pointer is modified, but the size is always 3 in the current implementation, so that's not really necessary to get it to work.
As far as I can see, this should be fixed now. In theory, the other two warnings should be gone, too, but I didn't test that thoroughly (only a quick test with gcc 7.4.0 in the Windows 10 Bash using the command line
gcc -Wall -oa09 a09.c
which kept its mouth shut).