The International Simutrans Forum

 

Author Topic: [patch] compiler warnings  (Read 2524 times)

0 Members and 1 Guest are viewing this topic.

Offline ras52

  • *
  • Posts: 89
[patch] compiler warnings
« on: October 09, 2012, 02:58:00 PM »
When run with -Wall (which the simutrans Makefile includes), gcc 4.5.x and above gives an error whenever the return value of fread, fwrite, etc. are ignored.  The simutrans code ignores these return values very frequently (and, to be honest, it's fairly harmless to do so).  The attached patch suppresses all these warnings, which vastly decreases the number of compiler warnings produced.  I could have done this by adding -Wno-unused-results to the Makefile, but earlier gccs don't have this option and will fail if an unknown option is given.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 10818
  • Languages: De,EN,JP
Re: [patch] compiler warnings
« Reply #1 on: October 09, 2012, 09:23:28 PM »
Using -Wall and then removing some again breaks the intention of -Wall, or? ;)

I rather not like to add such things to the code. When you add -Wall to CC_FLGAS (or wherever) in you config.defualt you could as well add this there too.

Offline ras52

  • *
  • Posts: 89
Re: [patch] compiler warnings
« Reply #2 on: October 10, 2012, 12:46:15 AM »
Well, I didn't add -Wall to my CFLAGS: it's included by the standard Makefile.  It's simply that its meaning changes between each version of gcc.  Would you prefer me to develop a patch that explicitly tests each of the relevant return values and exits if they fail?  (Which, realistically, is all you can do in the specific circumstances.) I'm happy to do that if that's more helpful.

Offline Ters

  • Coder/patcher
  • Devotee
  • *
  • Posts: 5695
  • Languages: EN, NO
Re: [patch] compiler warnings
« Reply #3 on: October 10, 2012, 04:55:01 AM »
Fixing the warnings rather than silencing them seems like the best idea to me, though it's rather boring. And it's seldom harmless to ignore an error, and when reading data that's going to be used, it certainly isn't.

Offline ras52

  • *
  • Posts: 89
Re: [patch] compiler warnings
« Reply #4 on: October 10, 2012, 12:25:34 PM »
Fixing the warnings rather than silencing them seems like the best idea to me, though it's rather boring. And it's seldom harmless to ignore an error, and when reading data that's going to be used, it certainly isn't.

You're right, of course.  The attached patch fixes all of the obj_reader code, which was responsible for a large proportion of the warnings.