Re: C/C++ memory-order compiled definitions?
- From: "Ira Baxter" <idbaxter@xxxxxxxxxxxxxx>
- Date: Fri, 31 Oct 2008 09:30:34 -0500
"Nathan Mates" <nathan@xxxxxxxx> wrote in message
news:fYOdnToRIoWbx5fUnZ2dnUVZ_qninZ2d@xxxxxxxxxxxxxx
In article <er43wkuOJHA.4180@xxxxxxxxxxxxxxxxxxxx>,
Ira Baxter <idbaxter@xxxxxxxxxxxxxx> wrote:
Let calls the generated structs the DATABASE, since it is a funny
kind of precompiled database :-} Note that DATABASE is just a large
series of initailized structs with nothing obviuosly tying them
together except thier proximity in the source file.
You're relying on undefined/undocumented behavior on the part of
the compiler. That's not a recipe for long-term success.
[Is there any hope of getting a Microsoft compiler person to
weigh in on this discussion?]
Apparantly not. But then, the C language standard says nothing
about multithreaded execution, either, but its so important that
all modern compilers gaurantee their code to be multithread capable.
In fact, any "accidental" behavior of a tool that has persisted for
a long period of time will be used. And things which work
accidentally often gets "backwards compatibility preserved".
Preservation of ordering
of compiled top-level definitions worked in every C compiler I ever
met, or was at least supported. The GNU compilers can
rearrange top level definitions, but there's an optimization switch
-fno-toplevel-reorder which ensures order preservation.
If you *need*
a specific ordering, then you should be putting them into another
structure that puts them in that order, e.g.
struct DatabaseItem1 { .. };
struct DatabaseItem2 { .. };
struct DATABASE
{
DatabaseItem1 m_Item1;
DatabaseItem2 m_Item2;
};
I figured I might have to do something like this.
I don't really need a *specific* ordering of most
of the items. What I desperately need is a way
to group compiled entities into regions so that I
can tell that a pointer is making a reference into
that specific region.
As an example, I have the same problem with function ordering.
This application can sometimes "stop" an activitiy in mid-track,
and has to determine if the activity was executing in one
of a number of specific sets of C functions in order
to recover. The reasons behind all this are pretty
complicated, and motivated by the fact that I'm
running a highly parallel program with speculative
execution that may need to be undone.
My (legacy) scheme for handling that was:
void set1start(void) {}
void set1fn1() { ...}
void set1fn2() { ...}
...
void set1end(void){}
void set2start(void){}
void set2fn1() {...}
..
void set2end(void){}
Now, if the processor is executing somewhere inside set1fn2,
its PC (extracted by "undocumented behavior" of the compiler,
e.g., I know how to find it when I interrupt a thread)
is between the addresses of set1start and set2start.
At least up until I bumped in VS 2005.
Any suggestions as to how to make this work with MS compilers?
There some hints that pragmas can be used to "put things into sections",
but I don't see how that offers me any gaurantees that the
code is contiguous or ordered.
The gnu switch here offers me exactly what I need.
--
Ira Baxter, CTO
www.semanticdesigns.com
Nathan MatesHeinlein
--
<*> Nathan Mates - personal webpage http://www.visi.com/~nathan/
# Programmer at Pandemic Studios -- http://www.pandemicstudios.com/
# NOT speaking for Pandemic Studios. "Care not what the neighbors
# think. What are the facts, and to how many decimal places?" -R.A.
.
- Follow-Ups:
- Re: C/C++ memory-order compiled definitions?
- From: Igor Tandetnik
- Re: C/C++ memory-order compiled definitions?
- References:
- C/C++ memory-order compiled definitions?
- From: Ira Baxter
- Re: C/C++ memory-order compiled definitions?
- From: David Lowndes
- Re: C/C++ memory-order compiled definitions?
- From: Ira Baxter
- Re: C/C++ memory-order compiled definitions?
- From: Nathan Mates
- C/C++ memory-order compiled definitions?
- Prev by Date: Re: address in DLL
- Next by Date: Re: Why use UNICODE?
- Previous by thread: Re: C/C++ memory-order compiled definitions?
- Next by thread: Re: C/C++ memory-order compiled definitions?
- Index(es):
Relevant Pages
|