Newer gcc silently accepts mixing C Code and Declarations
Christian Stimming
stimming at tuhh.de
Thu Jul 3 00:25:35 CDT 2003
-----BEGIN PGP SIGNED MESSAGE-----
This is an issue that already showed up here and there occasionally, but I
just figured out it will become a major issue in the future:
The latest gcc (3.3) silently accepts mixing Code and Declarations in its C
code. Quoting from gcc info pages (gcc -> C Extensions -> Mixed
Declarations):
ISO C99 and ISO C++ allow declarations and code to be freely mixed
within compound statements. As an extension, GCC also allows this in
C89 mode. For example, you could do:
int i;
/* ... */
i++;
int j = i + 2;
(end quote)
However, in any gcc earlier than 3.3 (or any other compiler) this kind of
construct will simply issue a "syntax error" in the line with the second
declaration. It is therefore clear that this should be not used in gnucash's
code. BUT, unfortunately, gcc3.3 does not offer any command line switches to
turn off this particular gcc extension! I really dug through any available
information about gcc and tried and tried all sorts of -Wsomething, -std=c89,
- -ansi or whatever switches gcc has, but gcc3.3 keeps silently accepting this
construct. Which makes the behaviour here totally different between gcc3.3
and gcc3.2/1/... -- I really wonder why this is mentioned nowhere in the
release notes.
The only gcc switch that will issue a warning about this is "-pedantic". It
then says
warning: ISO C89 forbids mixed declarations and code
However, the "-pedantic" switch prints just a headache-causing long list of
warnings (including e.g. src/engine/Account.h:94: warning: comma at end of
enumerator list, and also warnings from <glib.h> and from g_assert()). This
switch is pretty useless for the current gnucash code.
So what do we do? First of all, if anybody happens to run a non-gcc3.3 and
discovers such a syntax error, then please don't start flaming the gcc3.3
folks but please simply go ahead and fix that. Second, does anyone know some
secret gcc switch that might enable again the detection of that problem? If
there is none, then, well, what do people think about making gnucash
- -pedantic proof... or do we simply live with those errors every now and then?
Cheers,
Christian
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2-rc1-SuSE (GNU/Linux)
iQCVAwUBPwNN1WXAi+BfhivFAQFWXQP/Xeu7uEHPEfC5C1mUfPdjWsgyuFziq7p+
jFgQCCC+oLVgXKk/aEIXSwce6ajIH6TW6y/yUMFXJGRDZx+HkxyxSruQCOWV6Fc3
Yo21Gkr5nncVBmdr3Hypr1pP2eNrsaInRNdoj/AjfxKJ/8zV614hIDSTAPNYi8Ed
UHhmJgYPkeQ=
=f5j/
-----END PGP SIGNATURE-----
More information about the gnucash-devel
mailing list