Re: [hatari-devel] Some findings

[ Thread Index | Date Index | More Archives ]

Le 04/09/2018 à 06:37, Thomas Huth a écrit :
On 2018-09-03 18:51, Nicolas Pomarède wrote:

Can't tell the reason for Troed's build ,

I've had a look at the build.log, and it failed during linking, not
during compiling.

but I fixed a "for loop" in
nc5380.c that required c11 or c99 options in gcc :

src/ncr5380.c:309:5: erreur: 'for' loop initial declarations are only
allowed in C99 or C11 mode
      for (int i = 0; i < 8; i++) {
src/ncr5380.c:309:5: note: use option -std=c99, -std=gnu99, -std=c11 or
-std=gnu11 to compile your code

gcc 4.9.2 is reporting this error, but the most recent gcc 8 doesn't
report it anymore.

That's an issue indeed - and it happens almost each time we copy some
code from a C++ project to Hatari. The problem is that GCC switched the
default setting for -std, it used to be gnu89, but since GCC 5.1, it is
gnu11 instead.

Since we want to keep C compatibility with older compilers, maybe we
should explicitely add options to Cmake in order to report this also
with more recent gcc ? Using the -std=option (but I don't know the
equivalent that was used in gcc 4.9) ; else the compilation issue might
go unnoticed as I guess most of us are compiling with recent gcc version.

I agree, we should set a value for -std in our CMakeLists.txt. The
question is: Which one? Do we want to enforce the old C syntax? Then we
should go with "-std=gnu89". Or are we fine allowing the newer syntax
now, too, especially with regards to the code that we copy from C++
projects? Then we should go with gnu99 or gnu11 instead. I personally
tend to use one of the last options to allow the newer syntax. Shall we
simply have a try with gnu11? It is marked as "incomplete" in GCC 4.x,
but at least for the "for"-loop initializers, it seems to work fine.


it's sure that the "for loop" init syntax is the most common case we encounter when importing code from other projects.

I don't know what minimal version of gcc we can expect on the various architecture where people are usually building Hatari ? (raspberry and so on). At one point, this syntax is allowed since 1999, so maybe it's time to support it in our code, I think 20 years later there should be a compiler on every arch/OS to support it.

Maybe gnu99 is just enough for now (or is there an equivalent or common syntax for clang too ?), as we don't intend to use all the newer C extension (neither use C++), just those that need changes when importing code from other projects.


Mail converted by MHonArc 2.6.19+