public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Is -fcommon reliable?
@ 2018-03-16 16:56 Robert Henderson
  0 siblings, 0 replies; only message in thread
From: Robert Henderson @ 2018-03-16 16:56 UTC (permalink / raw)
  To: gcc-help

Hi,

Consider the the following code:

  // Header foo.h:
  const double FooLength;
  const double FooMass;

  // Source file foo.c:
  #include "foo.h"
  const double FooLength = 4.2;
  const double FooMass = 10.5;

  // Source file bar.c:
  #include foo.h
  ...

This is non-standard C, but it is correct if you rely on the '-fcommon'
feature of GCC which merges tentative definitions across translation
units. I find '-fcommon' to be a convenient and useful feature because
it allows you to omit 'extern' specifiers on declarations of global
constants.

My question is: if I rely on '-fcommon' in this way in my own software,
is it likely to cause any problems for me down the line? For example,
are there any plans to deprecate '-fcommon' in GCC in the future?

Regards,

Rob Henderson

Additional notes:
 () The '-fcommon' functionality is described in K&R in a footnote (2nd
edition, Sect. A10.2, pg. 227) as an "alternate formulation, ... usual
in UNIX systems and recognised as a common extension by the Standard".
 () The GNU LD manual, Sect. 2.1, describes reliance on '-fcommon' as a
"somewhat sloppy practice".

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-03-16 16:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-16 16:56 Is -fcommon reliable? Robert Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).