On 10/07/2004, at 6:22 AM, Peter Grace wrote:

I've been fiddling with C/C++ on the AS/400 and am suffering from a
lack of rudimentary knowledge on how you do simple things (like,
return character arrays back to an RPG program)...

C doesn't have the concept of return parameters. C operates expecting the pointers specified in argv to be input parameters. The only return from a C program is via the return value. The only return value from a C *PGM object is an integer via the return statement (e.g., return(8)).

However, because all parameters are are passed to OS/400 *PGM objects via reference (convention rather than requirement) you can de-reference any of the argv pointers and copy the required data into your caller's storage. Not an intuitive C-like way of doing things but perfectly understandable to an OS/400 programmer.

*argv[1] = 'N';
argv[1][0] = 'N';
memcpy( argv[2], "NO", 2 ); /* No null-terminator rubbish */
int i;
i = *(int*)arvg[3]; /* Presuming the caller passed an integer */
*(int*)argv[3] = i; /* Presuming the caller expects an integer returned */

As long as you know what the call interface is then you can accept and return any data type.

Are there any redbooks or documentation on the internet relating to
"How to program in ILE-C for dummies!"

There used to be a couple of books written from a 400 perspective:

Common Sense C by Paul Conte
C for RPG Programmers by Jennifer Hamilton

I think they are both out of print now. The IBM porting web site has some information that may prove helpful.

I've got several years of C programming experience so I know the
syntax and highlights.. I know there must be some kind of extensions
(through external API's and such) that make tasks like creating
subfile programs and such a breeze...

No such luck. In C you get to do everything the hard way (just like C programmers). You can call the external APIs listed in the a API section of the Information Centre (just remember that an API definition of CHAR(*) is not a char pointer but rather a pointer to a buffer) to get access to OS/400 objects, jobs, spooled files, and much other stuff. ILE C has record I/O extensions to handle native I/O. See the various _Rxxxx functions (e.g., _Ropen, _Rread, etc.).

For subfiles you would use:
        dbf = _Ropen( database file )
        dspf = _Ropen( display file )
        _Rformat( dspf, subfile )
        for (i=1; 1<= rcdCount; i++)
                _Rreadn( dbf, &record, rcdLen, .... )
                _Rwrited( dspf, &record, rcdLen, i )
        _Rformat( dspf, subfile control )
        _Rwrite( dspf )
        _Rclose( dspf )
        _Rclose( dbf )

Modify the structure as appropriate for load-all, page-at-a-time, and page=size subfiles.

Any help/links to docs would be greatly appreciated!

Only the C Programmer's Guide, C Language Reference, ILE C for OS/400 Run-Time Reference, and the MI Library Reference.

They are very helpful but much of it makes sense only if you also know how the 400 operates.

Simon Coulter.
   FlyByNight Software         AS/400 Technical Specialists

   Phone: +61 3 9419 0175   Mobile: +61 0411 091 400        /"\
   Fax:   +61 3 9419 0175                                   \ /
                 ASCII Ribbon campaign against HTML E-Mail  / \

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2019 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].