Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #111997

Re: Style question: Declaration of globals in header file

From Steve Keller <keller@no.invalid>
Newsgroups comp.lang.c
Subject Re: Style question: Declaration of globals in header file
Date 2017-06-12 11:07 +0200
Organization Aioe.org NNTP Server
Message-ID <ohllk8$17hb$1@gioia.aioe.org> (permalink)
References <oh6p0c$e9k$1@gioia.aioe.org> <6eedb0da-29b9-8a0e-fbec-06a99c76f2bb@verizon.net>

Show all headers | View raw


Hm, I wonder why all of you state that having

	int foo;

in multiple translation units violates the standard.  In 6.9.2 this is
called a tentative definiton and my understanding has always been that
you can have multiple tentative definition plus zero or one definitions
with an initializer.  In 6.9.2 the standard at least says that you can
have multiple tentative definition in one translation unit (from some
c99 draft):

[#4] EXAMPLE 1

    int i1 = 1;         // definition, external linkage
    static int i2 = 2;  // definition, internal linkage
    extern int i3 = 3;  // definition, external linkage
    int i4;             // tentative definition, external linkage
    static int i5;      // tentative definition, internal linkage

    int i1;             // valid tentative definition, refers to previous
    int i2;             // 6.2.2 renders undefined, linkage disagreement
    int i3;             // valid tentative definition, refers to previous
    int i4;             // valid tentative definition, refers to previous
    int i5;             // 6.2.2 renders undefined, linkage disagreement

    extern int i1;      // refers to previous, whose linkage is external
    extern int i2;      // refers to previous, whose linkage is internal
    extern int i3;      // refers to previous, whose linkage is external
    extern int i4;      // refers to previous, whose linkage is external
    extern int i5;      // refers to previous, whose linkage is internal

All compilers I know allow multiple tentative also in several
translation units and implement this by putting foo into the common
block (i.e. not .bss or .data section) and the linker allows mutliple
object files to have the same symbol in their common block.  Even the
relatively new LLVM/clang does it that way.

So now I wonder if my understanding of tentative definitions is
totally wrong.  Or do you think about C++ here?  I know that C++'s
rules are more strict.  In C++

	int foo;

normally goes into .bss section so you can't have multiple definitions
of it.

Steve

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Style question: Declaration of globals in header file Steve Keller <keller@no.invalid> - 2017-06-06 19:33 +0200
  Re: Style question: Declaration of globals in header file "James R. Kuyper" <jameskuyper@verizon.net> - 2017-06-06 14:21 -0400
    Re: Style question: Declaration of globals in header file Steve Keller <keller@no.invalid> - 2017-06-12 11:07 +0200
      Re: Style question: Declaration of globals in header file bartc <bc@freeuk.com> - 2017-06-12 11:03 +0100
      Re: Style question: Declaration of globals in header file Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-06-12 11:40 +0100
      Re: Style question: Declaration of globals in header file James Kuyper <jameskuyper@verizon.net> - 2017-06-12 07:33 -0400
        Re: Style question: Declaration of globals in header file Steve Keller <keller@no.invalid> - 2017-06-12 18:00 +0200
          Re: Style question: Declaration of globals in header file "James R. Kuyper" <jameskuyper@verizon.net> - 2017-06-12 12:11 -0400
            Re: Style question: Declaration of globals in header file Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-06-12 17:27 +0100
          Re: Style question: Declaration of globals in header file Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-06-12 17:18 +0100
          Re: Style question: Declaration of globals in header file supercat@casperkitty.com - 2017-06-12 09:44 -0700
      Re: Style question: Declaration of globals in header file supercat@casperkitty.com - 2017-06-12 07:55 -0700
        Re: Style question: Declaration of globals in header file Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-06-12 16:51 +0100
  Re: Style question: Declaration of globals in header file Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-06-06 19:21 +0100
  Re: Style question: Declaration of globals in header file Jorgen Grahn <grahn+nntp@snipabacken.se> - 2017-06-06 19:54 +0000
  Re: Style question: Declaration of globals in header file Andrey Tarasevich <andreytarasevich@hotmail.com> - 2017-06-06 18:37 -0700
    Re: Style question: Declaration of globals in header file supercat@casperkitty.com - 2017-06-07 07:54 -0700
      Re: Style question: Declaration of globals in header file David Brown <david.brown@hesbynett.no> - 2017-06-07 17:23 +0200
        Re: Style question: Declaration of globals in header file supercat@casperkitty.com - 2017-06-07 11:10 -0700
          Re: Style question: Declaration of globals in header file David Brown <david.brown@hesbynett.no> - 2017-06-07 22:13 +0200
            Re: Style question: Declaration of globals in header file supercat@casperkitty.com - 2017-06-07 14:57 -0700
              Re: Style question: Declaration of globals in header file David Brown <david.brown@hesbynett.no> - 2017-06-08 00:05 +0200
              Re: Style question: Declaration of globals in header file bartc <bc@freeuk.com> - 2017-06-07 23:19 +0100
                Re: Style question: Declaration of globals in header file supercat@casperkitty.com - 2017-06-07 16:16 -0700
              Re: Style question: Declaration of globals in header file Ian Collins <ian-news@hotmail.com> - 2017-06-08 12:56 +1200
                Re: Style question: Declaration of globals in header file David Brown <david.brown@hesbynett.no> - 2017-06-08 08:51 +0200
                Re: Style question: Declaration of globals in header file David Thompson <dave.thompson2@verizon.net> - 2017-07-09 22:43 -0400
                Re: Style question: Declaration of globals in header file supercat@casperkitty.com - 2017-07-10 08:46 -0700
                Re: Style question: Declaration of globals in header file Robert Wessel <robertwessel2@yahoo.com> - 2017-07-10 21:00 -0500
                Re: Style question: Declaration of globals in header file supercat@casperkitty.com - 2017-07-10 21:08 -0700
                Re: Style question: Declaration of globals in header file Robert Wessel <robertwessel2@yahoo.com> - 2017-07-11 01:18 -0500
                Re: Style question: Declaration of globals in header file bartc <bc@freeuk.com> - 2017-06-08 10:10 +0100
                Re: Style question: Declaration of globals in header file raltbos@xs4all.nl (Richard Bos) - 2017-06-17 18:08 +0000
            Re: Style question: Declaration of globals in header file "Patrick.Schluter" <Patrick.Schluter@free.fr> - 2017-06-10 08:36 +0200
    Re: Style question: Declaration of globals in header file Tim Rentsch <txr@alumni.caltech.edu> - 2017-06-09 10:09 -0700
      Re: Style question: Declaration of globals in header file supercat@casperkitty.com - 2017-06-09 12:17 -0700
  Re: Style question: Declaration of globals in header file Tim Rentsch <txr@alumni.caltech.edu> - 2017-06-09 09:52 -0700

csiph-web