From: Robert Henderson <rob@robjhen.com>
To: gcc-help@gcc.gnu.org
Subject: Is -fcommon reliable?
Date: Fri, 16 Mar 2018 16:56:00 -0000 [thread overview]
Message-ID: <43e6eebe-3ca5-ee5a-8f46-09a540e550ff@robjhen.com> (raw)
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".
reply other threads:[~2018-03-16 16:56 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=43e6eebe-3ca5-ee5a-8f46-09a540e550ff@robjhen.com \
--to=rob@robjhen.com \
--cc=gcc-help@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).