Re: Informix / C parameter passing
Posted in 1993
Note: This is (sort of) a continuation of the 'translate at warp speed' thread, but I changed the subject to reflect a changed emphasis. Many thanks to Jack Parker, Jonathan Leffler, Stuart Kemp, and Scott Ellard for help in improving various aspects of the C version of the translate function. To save bandwidth, I won't repost the whole thing, but I provide the following summary of topics that seem important, at least to me: 1. Jonathan has convinced me that it is better to use 'retquote' instead of 'pushquote' to return strings as function values. I was fooled because my *old* version of c4gl generates 'pushquote' followed by 'doretalloc', which is essentially what 'retquote' does. (Strange: My code which used 'pushquote' without 'doretalloc' passed a test run of 300,000 invocations on a Sun without an apparent problem; for Jack it crashed immediately on his HP, until he changed 'pushquote' to 'retquote'.) MORAL: Always use 'retquote'. 2. Stuart suggested using: while ( lo && old[lo-1] == SPACE ) lo--; old[lo] = NULL; ^^^^^ in place of: while ( old[lo-1] == SPACE ) lo--; old[lo] = NULL; This takes care of all-blank and/or zero length input strings. Obviously it should be done for all three input strings. This is an excellent improvement to make the code more robust. Basically, I goofed. 3. Stuart goes on to suggest that the routine should check whether the output string might be overflowed by the substitution. In the interest of speed, I made the conscious decision to NOT make this test, but did not document it. This may not be a great decision, but it is consistent with the common practice in C library functions such as 'strcpy' to not check for string overflow. Check your man pages; your library may vary. 4. Figuring out which abnormal conditions to check for ends up being a judgment call. In translate, I documented in comments my decision to not check the number of input parameters. Reading 2 and 3 above shows that I think it's important to check for "too short" strings, but not for "too long" strings. I'm not sure why I feel this way. It's traditional, but I don't ALWAYS follow tradition. If you want my enhanced version of the 'translate' routine, mail me and I'll send it to you. One final note: Since this is an Informix forum, I was amused that my C routine generated a LOT more comment than the 4GL version. Regards, Alan ___________________________ ______________________| R. Alan Popiel |__________________________ \\ Internet: | Martin Marietta, Tech Ops | / \\ alan@den.mmc.com | P.O. Box 179, M/S 5422 | Std disclaimers apply. / )Voice: | Denver, CO 80201-0179 USA | ( / 303-977-9998 |___________________________| (But you knew that!) \\ /________________________) (____________________________\\