× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: Re: Prototyping printf()
  • From: "Simon Coulter" <shc@xxxxxxxxxxxxxxxxx>
  • Date: Thu, 28 Sep 00 21:04:35 +1000
  • Importance: Normal

E
Hello Barbara,

You wrote:
>Simon, the problem is that RPG has too many different numeric types.  What
>should it pass for say 3.5?  RPG could adopt C's rules and only have 2
>basic numeric type (integer and double-float), so 3.5 would be passed as
>8F.  Or it could say that 3.5 was packed(2,1), or perhaps packed(15,5), or
>maybe packed(30,15).  Once the compiler has figured out what the passed
>type should be, you're right: it's easy.

Maybe I'm looking at this too specifically with regard to printf() but the 
compiler 
should simply pass the BYTES.  It knows how many bytes declared variables 
occupy so no 
issue there.  Choosing the numeric type is only an issue when the compiler 
doesn't know 
the data representation.  The only case I can think of is when literals are 
being used.  
With the current prototypes the compiler can cast the literal to the type 
defined on the 
prototype.  With what we have been suggesting the compiler would need some 
rules for 
handling literals.  Since there is already a precedent for passing numeric 
literals as a 
15,5 packed decimal value I think the compiler should stick with that.

Character data isn't an issue because you are already handling that with CONST 
or 
OPTIONS(*STRING) etc.

In the case of passing a varying list to printf() the compiler can use the 
declared 
length of any specified variables (in bytes) and 15,5 for numeric literals.  It 
is up to 
the programmer to obey the rules and ensure the format string matches the data 
actually 
passed.  So we get the following:

        printf('A string %s, an integer %i, a packed decimal %D(15,5)\n',
                        theString, anInt, 12.3)

If I stuff up the format for the packed decimal literal (say %D(7,2) for 
instance) then 
printf() prints garbage, gets a pointer error, or prints nothing.  My 
responsibility, not 
the compiler's since I'm not playing by its rules.  No worse than getting the 
order of 
the substitution data wrong.

What d'ya reckon?  Now we've got that resolved it's just a small matter of 
programming, 
right?  So we should see it in the next release, eh?  RDLMAO   :)

Regards,
Simon Coulter.

«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»
«» FlyByNight Software         AS/400 Technical Specialists       «»
«» Eclipse the competition - run your business on an IBM AS/400.  «»
«»                                                                «»
«» Phone: +61 3 9419 0175      Mobile: +61 0411 091 400           «»
«» Fax:   +61 3 9419 0175      mailto: shc@flybynight.com.au      «»
«»                                                                «»
«» Windoze should not be open at Warp speed.                      «»
«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»
+---
| 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 thread ...


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

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.