linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Richard Moser <nigelenki@comcast.net>
To: Glynn Clements <glynn.clements@virgin.net>
Cc: Micha Feigin <michf@post.tau.ac.il>,
	linux-c-programming <linux-c-programming@vger.kernel.org>
Subject: Re: "static const" attribute in C++ (How to ?)
Date: Thu, 01 Jul 2004 03:12:45 -0400	[thread overview]
Message-ID: <40E3B96D.4080507@comcast.net> (raw)
In-Reply-To: <16611.16213.876963.610967@cerise.nosuchdomain.co.uk>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1



Glynn Clements wrote:
| John Richard Moser wrote:
|
|
|>|>It doesn't matter. A #include directive simply inserts the contents of
|>|>the header file directly into the source code which is fed to the
|>|>compiler. The compiler doesn't care which file a given piece of code
|>|>comes from.
|>|>
|>|
|>| It is a problem since a header can be included more then once, and
|>
|>Umm.
|>
|>#import "foo.h"
|>
|>This includes only one time.  I'd only use this with Objective-C though.
|>
|>For C, and in general, you should use:
|>
|>#ifndef __FOO_H__
|>#define __FOO_H__
|>
|>....
|>
|>#endif /*__FOO_H__*/
|
|
| That only prevents against the header being included multiple times
| within a given compilation unit, which isn't the issue which was being
| discussed. The issue was that, if an lvalue is defined (as opposed to
| declared) in a header file, it will exist in every object file whose
| source code included the header.
|

yeah, externally linked rather than staticly linked.  If you declare
them static, they won't be associated with an object symbol, thus it's
like they don't exist in relation to linking multiple objects together.

It goes like this:

int foo; /*We can say 'extern int foo' somewhere and access this from
another compilation unit*/
static int bar; /*This we can't.*/

| The key point is that C++ appears to treat initialised "static const"
| members as compile-time constants, not as lvalues. Thus, they don't
| exist in any object file, and so the problem of them existing in
| multiple object files doesn't arise.

Actually, they're the same as regular consts; they just don't get an
exported symbol, so they're invisible to the other compilation units.
They STILL get a position in the data segment!

|
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFA47lshDd4aOud5P8RAumVAJ9CmfPM1lUlOvDQjT3Dz8CG9ayg4QCZAekl
e5/IVRksVVq0HldmWYFDcv8=
=6vVS
-----END PGP SIGNATURE-----

  parent reply	other threads:[~2004-07-01  7:12 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-28 22:46 "static const" attribute in C++ (How to ?) Luciano Moreira - igLnx
2004-06-28 23:52 ` Glynn Clements
2004-06-29 14:30   ` Luciano Moreira - igLnx
2004-06-29 17:26     ` Henry Margies
2004-06-29 19:10       ` Luciano Moreira - igLnx
2004-07-02  7:47         ` wwp
     [not found]           ` <40E56EFF.1030901@ig.com.br>
2004-07-02 14:30             ` Luciano Moreira - igLnx
2004-06-29 17:39     ` Glynn Clements
2004-06-29 14:32   ` Micha Feigin
2004-06-29 17:43     ` Glynn Clements
2004-06-30  1:33       ` Micha Feigin
2004-06-30  2:01         ` Glynn Clements
2004-06-30 23:42           ` Daniel Brockman
2004-07-01 22:33             ` Glynn Clements
2004-06-30 20:39         ` John Richard Moser
2004-06-30 22:31           ` Glynn Clements
2004-07-01  3:22             ` Micha Feigin
2004-07-01  4:27               ` Glynn Clements
2004-07-01  7:12             ` John Richard Moser [this message]
2004-06-29 19:08     ` Luciano Moreira - igLnx
  -- strict thread matches above, loose matches on Subject: below --
2004-07-02 10:20 Dinesh Ahuja
2004-07-02 14:29 ` Luciano Moreira - igLnx
2004-07-02 22:32 ` Glynn Clements
2004-07-03  0:12   ` Luciano Moreira - igLnx
2004-07-05  5:35     ` Dinesh Ahuja
2004-06-28 21:42 Luciano Moreira - igLnx
2004-06-28 21:52 ` Glynn Clements
2004-06-29  1:10 ` Micha Feigin

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=40E3B96D.4080507@comcast.net \
    --to=nigelenki@comcast.net \
    --cc=glynn.clements@virgin.net \
    --cc=linux-c-programming@vger.kernel.org \
    --cc=michf@post.tau.ac.il \
    /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 NNTP newsgroup(s).