Re: C/C++ memory-order compiled definitions?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"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 Mates
--
<*> 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.
Heinlein


.



Relevant Pages

  • Re: I/O with database blob
    ... In this case - yes it is poor db design.- Hide quoted text - ... It really depends on what you want to do with the database. ... compiler will probably store your struct differently. ... your current database files will be hosed, because the stored structs ...
    (comp.lang.php)
  • Re: I/O with database blob
    ... It really depends on what you want to do with the database. ... compiler will probably store your struct differently. ... your current database files will be hosed, because the stored structs ... If you want to store the data from your structs in a database, ...
    (comp.lang.php)
  • Re: access(FULLPATH, xxx);
    ... with "trial& error" to just silence the compiler. ... void *foo); ... given that the language in the specification _was_ abiguous and both ... documentation was paramount. ...
    (freebsd-questions)
  • Re: fields for methods?
    ... void A::foo{ ... but only by a compiler that is allowed to ... int static_instance i = 0; ... it totally breaks the idea of encapsulation, which is the reason a lot ...
    (comp.programming)
  • compiler and metadata, request opinions...
    ... a lot of the upper/middle compiler machinery is still lacking (such as ... embed the metadata directly into the object modules (the reason being that ... request for a particular piece of information is embedded in a symbol (sort ... it will be loaded into an in-memory version of the database. ...
    (comp.compilers)