|
>Date: Sun, 24 Sep 2000 10:36:58 -0700
>From: "Eric N. Wilson" <doulos1@home.com>
>
>> printf() is a C function that expects a format string followed by zero
or more
>> substitution values....
>
>I had a long discussion about this and what you are asking for is the
>same thing I wanted. Support for the variable number of arguments that
>C supports (indicated in the function prototype as '...'). Basically I
>got the answer of not anytime soon if ever at all. Everyone was 'so'
>helpful by pointing out that I could prototype the different calls
>that I needed to printf.(Which I already knew and was not asking
>about)
C can support the ellipsis because it has only has 3 basic types: int,
double, pointer. No matter what it sees as a parameter, it knows what
to actually put on the parameter stack (*usually* what the programmer
intended. 'a' gets passed as a 4-byte int, 1.3 gets passed as a double,
"abcde" gets passed as a pointer. The problem is that RPG has many
more basic types than RPG does.
I'm sure you all know how to call printf generically with a single
prototype, but just in case ... Rather than trying to code this:
printf ('You have %d pending orders.' + newline
: num)
you code this:
printf ('%s' + newline
: 'You have ' + %trim(%char(num)) + ' pending orders.')
As far as I know, other than %p, you can do any formatting in RPG that
you can with printf. For %p formatting, you could write a procedure
like this:
P fmtPointer b
D fmtPointer pi 16a
D pointer * value
D buf s 17a
C callp sprintf (buf : '%p' : pointer)
C return buf
P e
Perhaps someday, ILE will have "externally-described" procedures, and RPG
will have good support for variable-typed parameters. I don't think
printf and its dot-dot-dot friends are a good model for this, though.
Barbara Morris, IBM Toronto Lab, RPG Compiler Development
+---
| 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-2025 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.