1) String constants are copied before returning, e.g.
*retstring = istrdup("atan2: must pass 2 arguments");
Why is this? It seems to work just as well todo

*retstring = "here is the return value";

This is because you want to explicity allocate memory for the string which MetaCard can use and dispose of. A string constant is allocated locally in your external and could potentially make bad things happen when MetaCard tries to read from that spot in memory (or dispose of the memory).

It may be the case that the memory is dealt with so quickly that the risk is small with such a small return value, but you could potentially get into trouble by way of bad luck, platform differences, and/or the size of the return value.

2) To indicate a successful call to a handler, it is doing
*retstring = (char *)calloc(1, 1);
What is the significance of the 1 byte? It seems returning NULL works
just as well and it's one less function call to make.


Most likely MetaCard checks for NULL, in which case this is ok- but if Metacard is expecting a pointer, it's more "correct" to give it one. If the engine were to try to read from that pointer after you set it to NULL, it could crash your app.

All this is doing is creating an empty string: strings are terminated with a NULL byte, so the 1 byte is just the "end-of-string" marker with no string data before it.

HTH






------------------------------
Brian Yennie
Chief Technology Officer
QLD Learning, LLC
www.QLDLearning.com

PH: (904)-997-0212
EMAIL: [EMAIL PROTECTED]
-------------------------------

Reply via email to