<HTML><FONT FACE=arial,helvetica><BLOCKQUOTE CITE STYLE="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px" TYPE="CITE"><FONT COLOR="#000000" FACE="Geneva" FAMILY="SANSSERIF" SIZE="2">1) String constants are copied before returning, e.g.<BR>
*retstring = istrdup("atan2: must pass 2 arguments");<BR>
Why is this? It seems to work just as well todo</FONT><FONT COLOR="#000000" FACE="Geneva" FAMILY="SANSSERIF" SIZE="2"><BR>
</FONT><FONT COLOR="#000000" FACE="Geneva" FAMILY="SANSSERIF" SIZE="2">*retstring = "here is the return value";</FONT><FONT COLOR="#000000" FACE="Geneva" FAMILY="SANSSERIF" SIZE="2"><BR>
</BLOCKQUOTE></FONT><FONT COLOR="#000000" FACE="Geneva" FAMILY="SANSSERIF" SIZE="2"><BR>
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).<BR>
<BR>
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.<BR>
<BR>
<BLOCKQUOTE CITE STYLE="BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px" TYPE="CITE"></FONT><FONT COLOR="#000000" FACE="Geneva" FAMILY="SANSSERIF" SIZE="2">2) To indicate a successful call to a handler, it is doing<BR>
*retstring = (char *)calloc(1, 1);<BR>
What is the significance of the 1 byte? It seems returning NULL works<BR>
just as well and it's one less function call to make.</FONT><FONT COLOR="#000000" FACE="Geneva" FAMILY="SANSSERIF" SIZE="2"><BR>
</BLOCKQUOTE></FONT><FONT COLOR="#000000" FACE="Geneva" FAMILY="SANSSERIF" SIZE="2"><BR>
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.<BR>
<BR>
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.<BR>
<BR>
HTH<BR>
</FONT><FONT COLOR="#000000" FACE="Geneva" FAMILY="SANSSERIF" SIZE="2"><BR>
<BR>
<BR>
<BR>
<BR>
<BR>
------------------------------<BR>
Brian Yennie<BR>
Chief Technology Officer<BR>
QLD Learning, LLC<BR>
www.QLDLearning.com<BR>
<BR>
PH: (904)-997-0212<BR>
EMAIL: Yennie@aol.com<BR>
-------------------------------<BR>
</FONT><FONT COLOR="#000000" FACE="Geneva" FAMILY="SANSSERIF" SIZE="2"></FONT></HTML>