#4753: fix MXE compiler warnings
-------------------------------------------------+-------------------------
 Reporter:  Forgon                               |             Owner:
     Type:  patch (an actual patch, not a        |            Status:  new
  request for one)                               |         Milestone:
 Priority:  normal                               |  unspecified
Component:  other                                |           Version:
 Keywords:                                       |  git/master
 Blocking:                                       |        Blocked By:
                                                 |  Operating System:  All
                                                 |  /Non-Specific
-------------------------------------------------+-------------------------
 MXE ensures that all code is position-independent. Warzone 2100 uses the
 "-fPIC" compile flag, leading to several unnecessary warnings like:

 {{{
 connecthostport.c:1:0: warning: -fPIC ignored for target (all code is
 position independent)
  /* $Id: connecthostport.c,v 1.15 2015/10/09 16:26:19 nanard Exp $ */
  ^
 }}}

 [https://gcc.gnu.org/ml/gcc-help/2015-08/msg00091.html GCC developers
 expect users not use "-fPIC" for Windows targets]. Consequently, we no
 longer do.

 ----

 The MSVC-specific pragma [https://msdn.microsoft.com/en-
 us/library/7f0aews7(v=vs.140).aspx "comment"] was  executed on other
 platforms and thus not recognised:

 {{{
 In file included from uECC.c:84:0:
 platform-specific.inc:12:0: warning: ignoring #pragma comment  [-Wunknown-
 pragmas]
  #pragma comment(lib, "crypt32.lib")
  ^
 platform-specific.inc:13:0: warning: ignoring #pragma comment  [-Wunknown-
 pragmas]
  #pragma comment(lib, "advapi32.lib")
  ^
 }}}

 ----

 The format specifier macros 'PRIu32', 'PRIu64' and 'PRId64' were not
 properly expanded with MXE, causing warnings such as:

 {{{
 In file included from string_ext.h:24:0,
                  from frame.h:44,
                  from trig.h:29,
                  from trig.cpp:31:
 trig.cpp: In function 'bool trigInitialise()':
 debug.h:71:58: warning: unknown conversion type character 'l' in format
 [-Wformat=]
     (void)_debug(__LINE__, LOG_INFO, function, __VA_ARGS__), \
                                                           ^
 debug.h:98:4: note: in expansion of macro 'ASSERT_FAILURE'
     ASSERT_FAILURE(expr, #expr, location_description, function,
 __VA_ARGS__) \
     ^
 debug.h:109:2: note: in expansion of macro 'ASSERT_HELPER'
   ASSERT_HELPER(expr, AT_MACRO, __FUNCTION__, __VA_ARGS__)
   ^
 trig.cpp:76:3: note: in expansion of macro 'ASSERT'
    ASSERT((uint32_t)iSqrt(lower) == test, "Sanity check failed, sqrt(%"
 PRIu64") gave %" PRIu32" instead of %" PRIu64"!", lower, i64Sqrt(lower),
 test);
    ^
 debug.h:71:58: warning: format '%u' expects argument of type 'unsigned
 int', but argument 5 has type 'uint64_t {aka long long unsigned int}'
 [-Wformat=]
     (void)_debug(__LINE__, LOG_INFO, function, __VA_ARGS__), \
                                                           ^
 debug.h:98:4: note: in expansion of macro 'ASSERT_FAILURE'
     ASSERT_FAILURE(expr, #expr, location_description, function,
 __VA_ARGS__) \
     ^
 debug.h:109:2: note: in expansion of macro 'ASSERT_HELPER'
   ASSERT_HELPER(expr, AT_MACRO, __FUNCTION__, __VA_ARGS__)
   ^
 trig.cpp:76:3: note: in expansion of macro 'ASSERT'
    ASSERT((uint32_t)iSqrt(lower) == test, "Sanity check failed, sqrt(%"
 PRIu64") gave %" PRIu32" instead of %" PRIu64"!", lower, i64Sqrt(lower),
 test);
    ^
 }}}

 The solution was to use the MXE-specific macros '!__USE_MINGW_ANSI_STDIO'
 and '!__MINGW_PRINTF_FORMAT' as described
 [https://sourceforge.net/p/mingw-w64/wiki2/gnu%20printf/ here].

 ----

 A typo caused this warning:

 {{{
 frontend.cpp:175:27: warning: multi-character character constant
 [-Wmultichar]
   wchar_t  wszDest[250] = {'/0'};
                            ^
 }}}

 ----

 Parentheses were added around assignments used as truth values to avoid
 compiler warnings like:

 {{{
 exchndl.cpp: In function 'void ExchndlSetup(const char*)':
 exchndl.cpp:1375:61: warning: suggest parentheses around assignment used
 as truth value [-Wparentheses]
   if (dwRetVal = GetCurrentDirectoryW(MAX_PATH, miniDumpPath))
                                                              ^
 }}}

--
Ticket URL: <http://developer.wz2100.net/ticket/4753>
Warzone 2100 Trac <http://developer.wz2100.net/>
The Warzone 2100 Project
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Warzone2100-project mailing list
Warzone2100-project@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/warzone2100-project

Reply via email to