1. Undocumented "printf()" funnies

Hi, some observations with Eu 2.5a:

If you leave out the "%" symbol in a printf, then its not an error,
you simply get the string within the quotes printed. Would it not be better
to either document this, or have euphoria return "Unknown printf format"
as it does if you tried printf(1,"%k",0) Where "%k" is the rubbish demo.

Most incorrect formatting attempt within the printf quotes is not picked up
by initial parsing, only at execution time. Since you cannot use variables
within the quotes, there is no reason not to have this parsed? 

Attempting to use two decimal places is also unsupported, but it does
not give a parse error, but simply a strange result:

atom a
a = 100000001
printf(1,"%3.3.3d",a) 

will display ".3ld"  (Where does the "l" come from?)

This is also the case with eu2.4 official.
Yes, I know I can get the result I want with multiple printf's but this is
to demonstrate the problem. I also know that pretty print is not printf!

Regards,
Alan

new topic     » topic index » view message » categorize

2. Re: Undocumented "printf()" funnies

Alan Oxley wrote:
> 
> Hi, some observations with Eu 2.5a:
> 
> If you leave out the "%" symbol in a printf, then its not an error,
> you simply get the string within the quotes printed. Would it not be better
> to either document this, or have euphoria return "Unknown printf format"
> as it does if you tried printf(1,"%k",0) Where "%k" is the rubbish demo.
> 
> Most incorrect formatting attempt within the printf quotes is not picked up
> by initial parsing, only at execution time. Since you cannot use variables
> within the quotes, there is no reason not to have this parsed? 
> 
> Attempting to use two decimal places is also unsupported, but it does
> not give a parse error, but simply a strange result:
> 
> }}}
<eucode>
> atom a
> a = 100000001
> printf(1,"%3.3.3d",a) 
> </eucode>
{{{

> will display ".3ld"  (Where does the "l" come from?)
> 
> This is also the case with eu2.4 official.
> Yes, I know I can get the result I want with multiple printf's but this is
> to demonstrate the problem. I also know that pretty print is not printf!
> 
> Regards,
> Alan
> 


Hi

Thats normal behaviour, and how its supposed to work, in fact its a 'cut down'
version of c fprintf

the % tells the parser there's a formatting character coming
the 'd' 's' 'f' tell it the type (there is no 'c' in eu)
the numbers inbetween tell it how to print it
eg

printf(1,"%d", {12})
12

printf(1, "%03d", {12})
012

printf(1, "%10s", {"Hello"})
     Hello

printf(1, "%-10s%-10s", {"Hello", "World"})
Hello     World

printf(1, "%-14.14s", {"Hello world its a nice day isn't it"} )
Hello world it

printf(1, "%8.2f\n8.2f", {123.5678567, 45.897565432})
  123.56
   45.89

etc.

If a formatting character isn't found after a number its ignored, hence
%3.3.3d
is basically just ignored, and I've no idea where the l comes from!
(Probably just garbage)

if you want a % sign, then use 2 together

Chris




http://members.aol.com/chriscrylex/euphoria.htm
http://uboard.proboards32.com/

new topic     » goto parent     » topic index » view message » categorize

3. Re: Undocumented "printf()" funnies

Chris, 

I'm not a C programmer, and I wouldn't know about C's fprintf.
I don't think a EU user should need to! So, I'd like this printf behaviour
documented, and better initial parse syntax checking of the format
argument. 

Whats you view on better syntax checking on the format argument?
Getting "garbage" instead of an error message is not that friendly, yes?

Regards
Alan

new topic     » goto parent     » topic index » view message » categorize

4. Re: Undocumented "printf()" funnies

Alan Oxley wrote:

> Hi, some observations with Eu 2.5a:

Eu 2.5 beta has been released some time ago!

> If you leave out the "%" symbol in a printf, then its not an error,
> you simply get the string within the quotes printed. Would it not be better
> to either document this, or have euphoria return "Unknown printf format"
> as it does if you tried printf(1,"%k",0) Where "%k" is the rubbish demo.

I agree. A more specific error message would be even better, e.g.:
"No % character found in the format string."

> Most incorrect formatting attempt within the printf quotes is not picked up
> by initial parsing, only at execution time. Since you cannot use variables
> within the quotes, there is no reason not to have this parsed?
>
> Attempting to use two decimal places is also unsupported,

Hm???

> but it does not give a parse error, but simply a strange result:
>
> }}}
<eucode>
> atom a
> a = 100000001
> printf(1,"%3.3.3d",a)
> </eucode>
{{{


That's a strange format string, so you get a strange result. blink
As far as I can see, this format string does not correspond to the
documentation.
And it certainly is *not* the proper format string for two decimal
places. Use e.g. the following to display two decimal places:

atom a
a = 12345.678
printf(1, "%8.2f", {a})


<snip>

Regards,
   Juergen

-- 
How do I quote correctly in e-mail and news?
http://www.netmeister.org/news/learn2quote.html

new topic     » goto parent     » topic index » view message » categorize

5. Re: Undocumented "printf()" funnies

On Fri, 04 Feb 2005 02:32:44 -0800, Alan Oxley
<guest at RapidEuphoria.com> wrote:

>Since you cannot use variables
>within the quotes, there is no reason not to have this parsed? 
You can use variables or any expression, eg
printf(fn,sprintf("%%0%dd",colwidth),val), or
printf(fn,"%0"&sprint(colwidth)&'d',val)

Suppose you have eg  printf(file[i],format[i],valueset[i]). It should
be perfectly legal for this to reduce to printf(1,"hello",{}). Hence
there is no absolute need for the format string to contain % at all.

I would agree that the format string should contain the same number of
valid format qualifiers as the length of the 3rd parameter, but Rob
has already stated he will not do this. If you want better error
checking you'll have to wrap printf yourself.

Regards,
Pete

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu