|
Thanks for the responses. The light did come on. I'm thinking more and more that I need to learn C. There are too many times now where at least a working knowledge of C is neccessary even in RPG. Joe Teff I wrote: >I'm not a C programmer and I'm a little confused with NULL terminated >strings. If I see the following line of code, this is supposed to create a >NULL terminated string, correct? > > C Eval SomeFld = SomeText + x'00' > >I guess NULL doesn't mean the absence of a value, rather just all zeros. > >Where I get confused is the Options(*string) keyword on a procedure. >Does that automatically append the x'00' onto the end of whatever >non-blank text is in the field? Hans wrote: >Almost. Yes, it automatically adds the X'00' onto the end of >your string, but all characters, including blanks. If you >don't want blanks included in your string value, you need to >use %trim or %trimr. > >A bit more precisely, options(*string) gives you a pointer to >some temporary storage location that contains your string >value with the x'00' character at the end. > >To illustrate, here's the example I posted last week: >------------------------------------------------------------ >H dftactgrp(*no) bnddir('QC2LE') >D atol pr 10i 0 extproc('atol') >D * value options(*string) >D num s 10i 0 >C eval num = atol('1234') >C num dsply >C eval *inlr = *on >------------------------------------------------------------ > >C function atol expects a null-terminated string as its only >parameter. Strings in C are often implemented by pointers to >null-terminated strings, thus a pointer value needs to be >passed. The string passed as parameter in RPG is saved in a >compiler-generated temporary variable, the null is appended to >the end, and the pointer to that location is passed to atol, >which doesn't even realize it's being called by a non-C program. > >You can also use null-terminated strings in other ways in RPG. >Let's say you have a pointer to a null-terminated string. You >can use BIF %str to treat that pointer as an RPG string value. >If pointer variable PTR contains the address of a null >terminated string, %STR(PTR) gives you the value of the string >in RPG character varying format. Jon Paris wrote: >Normally terminating with a null character (hex zeros) is done >prior to passing a pointer to the resulting string to a C function. >Those nice folks Hans and Barbara made this simpler by >introducing the Option(*String) as a qualifier to a pointer in a >prototype. When this is specified you have the option of doing >the work yourself and passing the pointer, or if you specify not >a pointer but a variable or expression, the compiler will do the >null termination etc. for you. >The complementary function is %Str which will convert a C type >string into a "real" RPG one. +--- | This is the RPG/400 Mailing List! | To submit a new message, send your mail to RPG400-L@midrange.com. | To subscribe to this list send email to RPG400-L-SUB@midrange.com. | To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com. | Questions should be directed to the list owner/operator: david@midrange.com +---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.