> From: Fr�d�ric Baillon [mailto:[EMAIL PROTECTED]]
> I'm currently working on a multi-segment project for Palm OS.
> It contains lots of  template instances. The problem is I can't 
> find how to fine tune the arrangement of the generated code to 
> avoid out of range 16-bit references.

I've been there too.  One important thing I learned is this: a template will
be instantiated as if it were hand-coded at the very bottom of the first
source file in which it is used, in the link order of the source files.
However, you can control this a little.  You can use '#pragma segment' to
force the template code to get put into a different code segment instead.
Put a '#pragma segment' line at the very _bottom_ of a source file, to force
all templates instantiated from that file to go into the desired segment.
(The compiler instantiates the templates "below" the last line of code in
the file, so the #pragma is obeyed.  It's a little weird.)  In your case you
may want a special segment just for templates.

Something like this:

        // file MyCode.cpp
        MyArray<int> arrayOfInts;
        /* ... code to use arrayOfInts ... */
        #pragma segment Template_Segment
        // end of file MyCode.cpp

Make sure MyCode.cpp is the first file in the link order in which template
MyArray<> is used.  Given this, the code for MyArray<> would end up in
Template_Segment instead of the default code segment for MyCode.cpp.

When in doubt, always check the linker map file to verify what code is
ending up in what segments.

-slj-

Reply via email to