[Swan-dev] Add -std=c99 to the compiler flags?

D. Hugh Redelmeier hugh at mimosa.com
Wed Feb 4 22:33:50 EET 2015


| From: Andrew Cagney <andrew.cagney at gmail.com>

| I've a simple motivation for this, I'd like to be able to use:
| 
|     for (int i = 0; i < 10; i++) { ... }
| 
| without -std=c99 I get a warning :-)

When the code was originally written, there was no c99.  I guess we
are long past those days and we should start taking advantage of the
new features.

I think declaring the variable in the for-head is one of the nicer
little features.  It goes along with my desire to keep variables as
local as possible.

There has been a strong temptation to use the same index variable in
sibling for statements: it cuts down in the number of declarations and
lines.  I think this new form eliminates that excuse.

Why does gcc require a flag?  Is using c99 so remarkable that it cannot be 
the default?  Is there any downside?  At least some things we already use 
were introduced in C99.

What other C99 features are worth using?

- local declarations mixed in with statements.  We've avoided this 
  (mostly) but it is sometimes quite nice.  Actually, this predates C99.
  This allows us to have fewer variables that are uninitialized.

- I think that we already use the struct and union member initializing 
  syntax

- Variable Length Arrays (VLAs) have been made optional-to-support in the 
  more recent standards so we should not use them.  Too bad: they could
  do what alloca was used for.

- inline functions -- we already use them.  How come we don't need 
  -std=c99 already?

- <stdbool.h>: we should replace the bool abstraction that I created.
  Should be trivial

- <inttypes.h> I think we already use it

- // we use this a bit.  I don't like it except in special cases.

- compound literals: might be useful



More information about the Swan-dev mailing list