stardot / b-em

An opensource BBC Micro emulator for Win32 and Linux
http://stardot.org.uk/forums/viewtopic.php?f=4&t=10823
GNU General Public License v2.0
112 stars 56 forks source link

Rp/clang warnings #190

Closed rjpontefract closed 1 year ago

rjpontefract commented 1 year ago

I fixed all of the warnings generated on macOS Ventura 13.2.1 with Apple clang version 14.0.0 (clang-1400.0.29.202).

I also built on Linux gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0 and no warnings were generated there either.

I haven't built this on Windows. Please can you let me know which compiler/dev environment you use on Windows so that I can set up the same?

rjpontefract commented 1 year ago

The problem with "int do_int = 0;" was due to clang not allowing a declaration directly after a label, whereas gcc does seem to allow it (the C standard doesn't allow it, so clang is arguably correct here). So the previous commit where it was moved after the "check_PMUintr:" label broke it with clang.

The original position of that code was inside the else block containing the label, hence the warning that the goto skipped the initialisation. Moving it to the containing block as it is now puts it in a scope where it is initialised regardless of the goto. We could move it here:

check_PMUintr:
                    cp14r0 |= ARMul_CP14_R0_FLAG2;
                    int do_int = 0;

so that a statement follows the label, or we could introduce an empty statement after the label like this:

check_PMUintr:
                    ;
                    int do_int = 0;
                    cp14r0 |= ARMul_CP14_R0_FLAG2;

The code in the current pull request builds warning free with both clang and gcc however, but one of the above might be neater.

rjpontefract commented 1 year ago

The off_t format specifier is a tricky one. On Linux with gcc it's defined as a long int:

typedef long int __off_t;

whereas on macos with clang it's defined as a __int64_t:

typedef __int64_t __darwin_off_t;
typedef __darwin_off_t off_t;

Both are 64 bit values but gcc needs %lx or %ld and clang needs %lld or %llx as the format specifier. Using %j and casting to intmax_t is portable but does require a C99 compliant compiler.

rjpontefract commented 1 year ago

I have another branch called rp/windows_fixes where I have changes that allow it to build and run with Visual Studio 2017. There are a lot of warnings from the compiler but no errors. I can fix some of the warnings in this branch if it would help. I haven't built it with mkcross.sh yet. I do have the cross compiler installed on Linux but I haven't built a cross compiled version of the allegro library yet. Any hints on how you did that would be appreciated. Also, the zip file for MingW would be appreciated.