Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: printf builtin

Peter Stephenson wrote:
> Also, I don't understand what's happening here.
>   % printf "The answer is %d\x0c" 13
>   The answer is -4265416
> I can't seem to get any of the numeric formats to work.  In fact, I can't
> get the string format to work either.  Maybe there's some portability
> problem with the val union?

It does seem to be that, since everything looks OK up to the call to
printf.  As a test, I got it to work with a nasty hack using a void * and
separate variables for different types.

One problem I can see is that val has an element `zlong'.  Unfortunately on
32-bit machines with the default --enable-lfs, whether or not actual large
file support is available, that's usually a long long, i.e. 64-bits.  This
will certainly confuse printf with a simple `%d' --- Solaris supports
`%lld' but that's unlikely to be completely portable.  I'm afraid that's
another argument for handling the printf codes internally.  However, if we
use matheval(), the only basic numeric types we need to handle are doubles
and zlongs, plus some casting to unsigned: check Src/Builtins/rlimits.c for
some existing support for outputting long long or quad integers via printf.
(I've never actually seen a quad myself.)

However, there seems to be another problem, since changing that to long or
int (which are supposed to be the same here but I'm paranoid --- although
strictly we should enforce %ld if we pass on a long) doesn't help.

Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 392070

The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
If you received this in error, please contact the sender and 
delete the material from any computer.

Messages sorted by: Reverse Date, Date, Thread, Author