[crossfire] Crossfire server code cleanup/janitorial

Kevin Zheng kevinz5000 at gmail.com
Tue Apr 22 18:19:48 CDT 2014


On 04/22/2014 03:20, Tolga Dalman wrote:
>> And to follow that, if there are features of a specific version of
>>  the language that would be useful, say the requirement is 'the 
>> compile you use must support foo.  foo is known to be supported in
>>  gcc x, visual studio y, ..  If your compiler is not listed, see if
>>  that option is supported if additional compiler flags are needed'
> 
> Exactly. My point is that the code MUST be compilable by a set of 
> specific toolchains by following a specific standard (e.g., C99). 
> Some C99 features will probably not work on all specified toolchains,
> thus, those must be omitted in the code. I see no need for checking
> for a specific compiler. Instead, I'd just assume it.

The problem is that now we have to explicitly define a list of features
that are allowed in the code. Technically, neither GCC nor Clang are C99
compliant because they lack certain floating type macros. This does not
concern us because we don't really care about floating point operations.

Likewise, I think it's a good idea to change the language standard to
C99, but only use features where it makes sense. If we do decide to
change language standard, there is no immediate need to jump in and use
every single new feature, either.

>>> I've seen recommendations to compile C using a C++ compiler. 
>>> However, if you refer to Bjarne Stroustrup's authoritative book 
>>> he admits that certain incompatibilities exist. C++ is no more 
>>> standard than C, and C is just as (maybe even more) portable as 
>>> C++.
> 
> No. I'm thinking of the GCC project -- they are doing it this way. 
> The incompatibilities are really restricted to struct initialization
>  and using C++ keywords as variables or functions (like new or
> class). BTW: that book is neither a good reference, nor a good C++
> tutorial, IMHO.

I'm still not sure why this would make the project more portable,
though. The major compiler toolchains support C just as well as C++,
with the notable exception of Visual Studio.

>> The other problem I think that can lead to is this - suppose some 
>> change is made that works fine when compiled in C mode but fails in
>> C++ mode for whatever reason - you now get the problem of whether
>> the developer making the change will actually care about that, and
>> depending on where that incompatibility is, whether they can
>> actually figure it out if they are a pure C programmer.
> 
> I had already compiled the crossfire 1.70 code with C++ using GCC 
> last year. I can't rembember any serious issues.

The choice of compiler should be left to the user. Since this is a
project written in C, the 'official' way to compile it should be a C
compiler. Note that 'official' only means that someone will get yelled
at if a change breaks the compilation.

Quite frankly, I still have the (possibly wrong) notion that the most
logical choice to compile a C program is a C compiler.

>> If anything, for full compatibility, compiling with different 
>> compilers with full warnings/strict mode may be better.
> 
> I tend to agree, though, I have had some bad experience in another 
> project with a lot of false-positives using VS 2008. Using GCC, I 
> would always recommend compiling with -W -Wall.

Right now the code seems to compile fairly cleanly.

>>> I'm in favor of doing this in the mid-term. We already have a 
>>> nice collection of compatability macros that can serve as a 
>>> crutch for compilers we do not obey C99.
>> 
>> And that can certainly be extended.  The addition of functions
>> like snprintf are worth supporting (as are strlcat and strlcpy if
>> those are part of some
> 
> TBH I have some problems with strlcat and strlcpy: they are neither 
> supported by ISO C, nor by POSIX. The glibc project repeatedly 
> refused to add those functions to the standard library. They offer no
> more functionality than strncpy and strncat. Conversely, they are a
> known source of potential bugs (a quick Google search for strlcpy and
> glibc will reveal the details).

While strlcat and strlcpy are not defined by any standards body, I
believe that they are superior to the normal functions and should be
used whenever possible. If you haven't noticed, I recently committed a
small chunk of platform-dependent code that uses these two functions
when available instead of our hacks around it.

>> standard), but those can also be easily checked for in autoconf, 
>> and if they fail to exist, some simple conditionals can check for 
>> that and private functions added.  Same for fixed sized types - the
>> native types used by the compiler can be used instead of the 
>> typedefs currently in place, but if those native types are not 
>> available (due to old version), a simple enough ifdef to use the 
>> typdef instead.
> 
> I guess, we're here in disagreement. If I understood you correctly, 
> you want to support old compilers, while my approach is to remove old
> cruft to make crossfire maintainable. What old toolchains are being
> used and which of them do you want to support and test ?

Right now Crossfire seems maintainable. Recently, several important bug
fixes were made, and few new features were introduced.

I am in favor of switching to the "standard" fixed-sized integer types.
It is trivial to make the appropriate definitions in a separate header
file for systems that do not already have these types.

>> I'd note that a lot of the goofy, ugly, or odd code exists because 
>> maps expect it that way.  Which is to say, some functions could 
>> potentially be made cleaner and simpler, but to do so would require
>> examining every map and making changes to some number (and 
>> depending on exactly what construct is being used, being able to 
>> detect those automatically might be hard).
> 
> I had in mind the networking, event processing/server loop, and 
> plugin codes.

Even then, some specifics would be useful. What are you suggesting for
networking or the server loops?

Personally I'd like to go back in time and get rid of plugins, but that
is an entirely different discussion. It will involve a *lot* of work for
not a ton of appreciable player benefit.

>> I'm all for fixing some of that, but it falls into the category of
>>  a lot of work with no direct/end user effect.  For programmers, 
>> there is cleaner code, but for players, things worked (or should 
>> work) exactly the same as before.  So those types of changes tend 
>> to be somewhat low priority just for that reason.
> 
> I agree, though, my contribution will certainly be in the coding 
> area. I leave the game play and game content creation to the experts
>  :)

At the end of the day, if you believe that certain changes are worth
your time making, please send a patch. The recent cleanups were made
because I wanted them and nobody objected to them.

Thanks,
Kevin Zheng


More information about the crossfire mailing list