From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26720 invoked from network); 24 Sep 2001 10:51:15 -0000 Received: from sunsite.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 24 Sep 2001 10:51:15 -0000 Received: (qmail 28761 invoked by alias); 24 Sep 2001 10:50:57 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 15863 Received: (qmail 28745 invoked from network); 24 Sep 2001 10:50:54 -0000 To: zsh-workers@sunsite.dk (Zsh hackers list) Subject: Re: PATCH: printf builtin In-reply-to: "Peter Stephenson"'s message of "Fri, 21 Sep 2001 15:55:40 BST." <1709.1001084140@csr.com> Date: Mon, 24 Sep 2001 11:50:06 +0100 Message-ID: <87.1001328606@csr.com> From: Peter Stephenson 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 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 prohibited. If you received this in error, please contact the sender and delete the material from any computer. **********************************************************************