At 12:45 PM 5/7/2004, you wrote:
Hi,

I'm creating a shared library (syslib-type) that in turn makes use of MathLib. Those of you who've used MathLib know that you include MathLib.c in your own project. MathLib.c defines a global variable to hold the refnum when the library is opened. Global variables are not allowed in shared libraries, so I'm told. Yet, when I placed the global variable in the .text segment of my shared library, like this:

UInt16 MathLibRef __attribute__ ((section (".text")));

it worked (meaning it compiled without errors or warnings, and I was able to successfully access MathLib functions in a test program)! Was this just a fluke, or can this be done safely and reliably?

I would guess that the only reason this would work would be that you were running on a device or simulator where memory protection was disabled. Putting the variable in the .text section puts it in read-only memory on almost all devices.


Why not implement your code as a C++ class where you can pass this MathLib ref around as one of the class instance members. While you can't use a lot of C++ in a shared library, a simple stack-based class should work fine and would simplify passing of "pseudo-globals". I used this technique in the original PACEInterface layer in the CW PNO tools.


-- Ben Combee, DTS technical lead, PalmSource, Inc. Read "Combee on Palm OS" at http://palmos.combee.net/



--
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to