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: Fri, 28 Feb 2003 13:56:00 -0000 [thread overview] Message-ID: <20030228135600.9537.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: Fri, 28 Feb 2003 08:49:50 -0500 (EST) Sorry, for the delay in responding, but Thursday evening is my guitar lesson so I had to head home early to prepare. Well, all the questions you raise boil down to the question: what is an address constant expression. Apparently, the compiler chooses to consider the initializer in line X to be one, while it doesn't for line Y. I cannot answer the question further than what I did in my previous mail, apart from the fact that line X has not cast (or, rather: a cast from one type to itself), while line Y has a (reinterpret_)cast from type module to incompatible type bar. It seems to me that a cast to a pointer should always have the same meaning. That is, when reinterpreting the bits, the meaning of those bits cannot imply a static context in one case and a dynamic in another. That seems too bizarre. So what is the next step? My code use to work with gcc 3.2 and now fails with gcc 3.3. My understanding is that gcc3.3 is scheduled for release very soon and I would like my code to work with it. What law firm do I need to hire to press my case as it seems the issue is an open question for the current version of g++. What if I get a note from Bjarne saying which way it's suppose to go? Just as an aside, independent of the validity of the PR in itself: why are you making it so particularly hard for the compiler to decide this? You are setting module::b to &module::storage; there is simple syntax to achieve this goal than the one you use, no? :-) The program I submitted is the simplest case I could construct to illustrate (what I perceive) as an issue (lawyer speak). The real program is an extensive thread-library for C++, called uC++: http://plg.uwaterloo.ca/~usystem/uC++.html When the thread library is booting up, I need to initialize, by hand, a few fields in a static data-structure, which ultimately gets initialized by its constructor. That is, during the boot sequence there are mutually recursive reference issues that can best be resolved by temporarily making one data structure *appear* initialized so the first step can complete and then actually initializing the data structure in the second step. To do this, I need to statically insert an address and a non-zero value into 2 fields of the data structure. Now I can't declare an instance of the data structure because that triggers a call to its constructor, so I have to statically allocate a block of storage that is the size of the data structure, pretend the storage is the data structure, hit the storage with the necessary values, use those values at the start of the boot sequence so it looks initialized, and then run the constructor on the storage (new(storage) foo) to get the storage initialized. (You asked for this.) The fundamental reason for the mutually recursive references is that a thread library has to replace malloc/free to make them thread safe (no I do not and will not use pthreads). Now malloc is called during _start, while booting the C++ runtime, but my malloc thinks the thread library is running and accesses the data structure that I statically initialize. I could use an initialization flag that is checked for each malloc, but it is possible to eliminate the check if the boot sequence can be tricked. After the C++ runtime is started, my library can start and properly initialize the data structure. Essentially, when boot strapping a system, it is necessary to perform some of these "unusual" operations. There are similar, but much more complex, issues when boot strapping an OS. However, the bottom-line is that I should not need to justify a legitimate use for some feature in the language. (What a programmer wishes to do in the privacy their own code is their business.) The feature is there for me to use, and should work correctly (modulo the current outstanding legal question). But I do not mind answering this question for inquiring minds. (Which is how you asked the question.)
next reply other threads:[~2003-02-28 13:56 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2003-02-28 13:56 Peter A. Buhr [this message] -- strict thread matches above, loose matches on Subject: below -- 2003-03-02 22:16 Wolfgang Bangerth 2003-02-27 23:16 Wolfgang Bangerth 2003-02-27 22:56 Peter A. Buhr 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=20030228135600.9537.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: linkBe 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).