public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: "Peter A. Buhr" <pabuhr@plg2.math.uwaterloo.ca>
To: nobody@gcc.gnu.org
Cc: gcc-prs@gcc.gnu.org,
Subject: Re: c++/9881: Incorrect address calculation for static class member
Date: Thu, 27 Feb 2003 22:56:00 -0000	[thread overview]
Message-ID: <20030227225600.11624.qmail@sources.redhat.com> (raw)

The following reply was made to PR c++/9881; it has been noted by GNATS.

From: "Peter A. Buhr" <pabuhr@plg2.math.uwaterloo.ca>
To: bangerth@ticam.utexas.edu
Cc: asharji@uwaterloo.ca, gcc-bugs@gcc.gnu.org, gcc-gnats@gcc.gnu.org
Subject: Re: c++/9881: Incorrect address calculation for static class member
Date: Thu, 27 Feb 2003 17:51:18 -0500 (EST)

    > Finally, your suggestion is not even
    > a work-around, because the original problem occurred in separate compilation
    > units, so the notion of moving the constructor in this case does not apply.
 
    At which point you are out of luck in any case, since the standard does 
    not give any guarantee about the order of initialization in case there are 
    more than one translation units.
 
 I think it does. All static variables in all translation units must be
 initialized before any global constructors in any translation unit. The static
 initialization is usually done by reading constants from the .data section or by
 the linker/loader. So if I initialize a static variable in one translation
 unit, it must be initialized before a constructor is run in any another
 translation unit. I think you are referring to the order of evaluation of
 global constructors across translation units, which is undefined.
 
    May other language lawyers decide this case, regards
 
 Let me change the program slightly and see if this clarifies the situation.
 
    #include <iostream>
    
    using namespace::std;
    
    struct bar {
        double p;
    }; // bar
    
    struct module {
        static double *b;
        static double storage;
    };
    
    class foo {
      public:
        foo() {
    	// the output for both values should be the same
    	cout << &module::storage << " " << module::b << endl;
        }
    };
    
    foo f; // print output
    
    bar v;
    double *module::b = &(((bar *)(&v))->p); // LINE X
    //double *module::b = &(((bar *)(&module::storage))->p); // LINE Y
    double module::storage = 0.0;
    
    int main() {
    }
 
 If you run this with gcc3.3, the output is:
 
 @awk[5]% a.out
 0x8049a50 0x8049a48
 
 Now comment out LINE X, and uncomment LINE Y and run again getting output:
 
 @awk[6]% a.out
 0x8049a78 0
 
 Zero (0) is not an acceptable address. BUT, the only different between these 2
 lines is the chunk of storage for the object. Notice this has nothing to do
 with the constructor. One case works and one doesn't. Is this not compelling?


             reply	other threads:[~2003-02-27 22:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-27 22:56 Peter A. Buhr [this message]
  -- strict thread matches above, loose matches on Subject: below --
2003-03-02 22:16 Wolfgang Bangerth
2003-02-28 13:56 Peter A. Buhr
2003-02-27 23:16 Wolfgang Bangerth
2003-02-27 22:06 Wolfgang Bangerth
2003-02-27 21:46 Peter A. Buhr
2003-02-27 21:40 bangerth
2003-02-27 18:22 bangerth
2003-02-27 18:06 asharji

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=20030227225600.11624.qmail@sources.redhat.com \
    --to=pabuhr@plg2.math.uwaterloo.ca \
    --cc=gcc-prs@gcc.gnu.org \
    --cc=nobody@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).