On Fri, Oct 17, 2014 at 5:01 PM, Erik de Castro Lopo mle+tools@mega-nerd.com wrote:
teor wrote:
I just looked over this patch and it looks safe and simple to commit (haven't have a chance to compile it yet though). The correct order of declaration, asserts, and initialisation / assignment has been preserved in the code.
If we commit this patch, we should probably change the C standard compiler flags to in the autoconf scripts to C89 as well. (Do we set those?)
This would stop any more C99 sneaking in...
The vast majority of Vladimir's patch was fix something call Mixed Declarations eg:
int i = 0 ; printf ("%d\n", i) ; int j = 1 ;
You can disallow these mixed declarations in C99 code using -Wdeclaration-after-statement which is probably better than downgrading everything to C89 for comaptibilty with one compiler.
Well, we've actually had that warning in place in Tor for a long time. We turned it off recently in the master branch. See Sebastian's message above above about the tickets where we turned it off, in particular:
https://trac.torproject.org/projects/tor/ticket/13233 https://trac.torproject.org/projects/tor/ticket/13230
The question here isn't, "What do we need to do to keep compatibility with C89" -- we've been doing that for ages. The question is, "Is there a compelling reason to maintain compatibility with C89 that overrides the benefits of modernizing a little bit."
Keep in mind that C99 is 15 years old now. Staying with C89 today feels rather a lot like staying with K&R C 15 years after C89 was standardized. Sure, some projects still were (and still are!) written in K&R style, but by 2004 it had become pretty uncommon.
Right now, the most compelling cases for staying with C89 I've heard are:
* Some people want to use paid versions of Visual Studio, and have paid for a version earlier than VS2013, and don't want to pay for a newer one. I sympathize with this: I've been on paid upgrade treadmills myself, and it's always tempting to save money by skipping steps in the upgrade treadmill. I've even paid for commercial compilers in my misspent youth.
* Some compilers for weird old hardware have never been upgraded to even rudimentary C99 support, and trying to build code with those weird old compilers is a good way to expose some bugs. I sympathize with this too: there was one guy who would always compile new versions of Tor on his old Irix boxes, and he always turned up a new warning or two when he did.
Do we have any other cases to think about here?
Personally, I think I'm still inclined to say that the day for a more modern style has arrived.
People should also be aware than even though VS2013 claims some C99 compatibility my recollection is that it still does not provide a standards conforming snprintf implementation.
Not to worry; we fake our own snprintf if the platform snprintf isn't comformant enough.