delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2024/12/06/23:38:12

DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 4B74cCj64086377
Authentication-Results: delorie.com; dmarc=pass (p=none dis=none) header.from=cygwin.com
Authentication-Results: delorie.com; spf=pass smtp.mailfrom=cygwin.com
DKIM-Filter: OpenDKIM Filter v2.11.0 delorie.com 4B74cCj64086377
Authentication-Results: delorie.com;
dkim=pass (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=dwtkwOkQ
X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BD1263858294
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1733546291;
bh=o7Hueg6qroIWEIXrKRBEq0zlDFkXgwJ1SDCJDnQXM/M=;
h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe:
List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:
From;
b=dwtkwOkQg118KrQAC7bCybHT+KZZrkZcLYvO5y3vRYi+9qBdBPANn0gFQGIBSOIUY
cu2WOgxg5oMYQlaM1J3+8oc/JN7YN74yUR09wo9NXaNlZsBOLLCNdaXoBsP1vkEIkJ
Od1dt4a0mbEX+lYRAx1VlU8gDkv9BVIyWKdkPOMU=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EC9583858CDB
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EC9583858CDB
ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1733546225; cv=none;
b=Gv9KLWDarzCzbheTd/v8yA6K30nBeY6CB3jHm/WGN8BB1vd+rnKayFQT1WQcAFuA4GPkeVeKJDiSDD/206p54aOTmH/jeTp8vOX/AIjZKEV8MPXmJSYJ/DYk6CJj96BblLJHZbH6QOgPm/ySE+io+V5okx9waQ/2CF1Cc2SdVNI=
ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key;
t=1733546225; c=relaxed/simple;
bh=DSvPpRAotdwjHC7Llp1zPyWj0OhnBjZD46IzuGGsaHI=;
h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From;
b=xirmWdoUY5mXW21R9zIIC4AQifaZkj8UpItxxMd1EFLvcLqRJwXwtMuqr+de2Et719u3BzYXhM6GmTmOWULnE19l9QDH/zuBKTA7Mvpk7sM3DVxaHPQOSJ/HrlDBlk9HyeAc5u38mz9tFTgPcaibAmSl2N7vopjkrZEYg88EObE=
ARC-Authentication-Results: i=1; server2.sourceware.org
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EC9583858CDB
X-Authority-Analysis: v=2.4 cv=XeEqz555 c=1 sm=1 tr=0 ts=6753d0f0
a=DxHlV3/gbUaP7LOF0QAmaA==:117 a=DxHlV3/gbUaP7LOF0QAmaA==:17
a=IkcTkHD0fZMA:10 a=QqZMSHYJS6Bt_lE2bjkA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10
Message-ID: <215b6100-1e73-4871-bb57-9a1a413781dc@Shaw.ca>
Date: Fri, 6 Dec 2024 21:37:03 -0700
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: Bug in handling of "1$", "2$" in printf format
To: cygwin AT cygwin DOT com
References: <CAAHpriN5K1=-i9mWir57+GAhp-=har8rqAAa-b0-1JUNE6PQtw AT mail DOT gmail DOT com>
Autocrypt: addr=Brian DOT Inglis AT Shaw DOT ca; keydata=
xjMEXopx9BYJKwYBBAHaRw8BAQdAPq8FIaW+Bz7xnfyJ1gHQyf2EZo5sAwSPy/bRAcLeWl/N
I0JyaWFuIEluZ2xpcyA8QnJpYW4uSW5nbGlzQFNoYXcuY2E+wpYEExYIAD4WIQTG63sbl+cr
2nyOuZiKvQKcH1E27wUCXopx9AIbAwUJCWYBgAULCQgHAgYVCgkICwIEFgIDAQIeAQIXgAAK
CRCKvQKcH1E276DmAP91Bt8kfJhKHYb9b2sao2fxwJFsl1GlRi516WKI0OkphQEA+ULITsPs
blfzSq+GgI7q4LPfRfTLy4Oo3gorlnhnfgnOOAReinH0EgorBgEEAZdVAQUBAQdAepgIsLwm
GQicfoIBaB9xHp63MQJqVCPbgPzESTg7EEwDAQgHwn0EGBYIACYWIQTG63sbl+cr2nyOuZiK
vQKcH1E27wUCXopx9AIbDAUJCWYBgAAKCRCKvQKcH1E27+zoAP4u2ivMQBAqaMeLOilqRWgy
nV2ATImz1p2v1H5P4kBiDwD3caPK1cxU5lijzuSDCjgtIpgF/avHbjA32fxJdIRwAA==
Organization: Inglis
In-Reply-To: <CAAHpriN5K1=-i9mWir57+GAhp-=har8rqAAa-b0-1JUNE6PQtw@mail.gmail.com>
X-CMAE-Envelope: MS4xfHBFM2aPLBiT/MPFvBsW9AGHXKLvHhiqoEJfkc7msAcOlGg5EycJ+fN7Rlm7p+yUu/FYf6vRU9idu7eElldBgaXvfZqpmqhN/3itO4rqP+D0R6ccK8+/
DW+8naeVRI8fF7Vy7agpo7PdwU2jMHlqhbAS1M65y2bAxnzy1m0mijv9AX2IgcZD7hMFGrcYffDLgQ==
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.30
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
From: Brian Inglis via Cygwin <cygwin AT cygwin DOT com>
Reply-To: Brian DOT Inglis AT Shaw DOT ca
Errors-To: cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com
Sender: "Cygwin" <cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com>
X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 4B74cCj64086377

On 2024-12-06 19:16, Keith Thompson via Cygwin wrote:
> The use of "1$", "2$" et al in printf format specifiers is a
> POSIX-specific feature.
> 
> On Cygwin (newlib) this is handled correctly in most cases, but one
> example I tried misbehaves.
> The output is correct on other implementations, including glibc and
> musl on Ubuntu.
> 
> This C program:
> 
> #include <stdio.h>
> int main(void) {
>      long long a = 123456789876543210;
>      double b=1.0/3;
>      printf("a:%2$8.8lld b:%1$10.2g\n", b, a);
> }
> 
> should produce this output:
> 
> a:123456789876543210 b:      0.33
> 
> Under Cygwin (fully updated), with "gcc c.c -o c && ./c", the output is:
> 
> a:140732550844138 b:  7.1e-315
> 

Confirmed with gcc 12.4 and minor tweaks to constant data types: printf is 
ignoring arg positions:

$ gcc --version && tail posnprintf.c && gcc -o posnprintf{,.c} && ./posnprintf
gcc (GCC) 12.4.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

#define I18LL 123456789876543210LL
#define THIRD 1.0/3.0
int main(void) {
     long long	a = I18LL;
     double	b = THIRD;
     printf("expected\ta:%18lld\tb:%10.6f\n",	I18LL, THIRD);
     printf("parameters\ta:%8.8lld\tb:%10.2g\n",		a, b);
     printf("positional\ta:%2$8.8lld\tb:%1$10.2g\n",	b, a);
     printf("ignoreposn\tb:%8.8lld\ta:%10.2g\n",		b, a);
}
posnprintf.c: In function ‘main’:
posnprintf.c:12:33: warning: format ‘%lld’ expects argument of type ‘long long 
int’, but argument 2 has type ‘double’ [-Wformat=]
    12 |     printf("ignoreposn\tb:%8.8lld\ta:%10.2g\n",         b, a);
       |                           ~~~~~~^                       ~
       |                                 |                       |
       |                                 long long int           double
       |                           %8.8f
posnprintf.c:12:43: warning: format ‘%g’ expects argument of type ‘double’, but 
argument 3 has type ‘long long int’ [-Wformat=]
    12 |     printf("ignoreposn\tb:%8.8lld\ta:%10.2g\n",         b, a);
       |                                      ~~~~~^                ~
       |                                           |                |
       |                                           double           long long int
       |                                      %10.2lld
expected	a:123456789876543210	b:  0.333333
parameters	a:123456789876543210	b:      0.33
positional	a:4599676421641834218	b:  2.1e-300
ignoreposn	b:4599676419421066581	a:  2.1e-300

-- 
Take care. Thanks, Brian Inglis              Calgary, Alberta, Canada

La perfection est atteinte                   Perfection is achieved
non pas lorsqu'il n'y a plus rien à ajouter  not when there is no more to add
mais lorsqu'il n'y a plus rien à retirer     but when there is no more to cut
                                 -- Antoine de Saint-Exupéry

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019