DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 4B75SAR34103110 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 4B75SAR34103110 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=mQsVpm+j X-Recipient: archive-cygwin AT delorie DOT com DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9FD1A385841D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; s=default; t=1733549288; bh=GWZ1PpS1RQxhcYLXF5wao3N3s03lKvpcPFeqbBI5XAU=; h=Date:Subject:To:Cc:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=mQsVpm+jvIEsSyAZ05tEGdvnB6PtfwlSs2m0NxXlO89ij19d5DBVP0n6VJMuzj3HD gTnozFBVXdMx008VnA7N+YcXsxPRl73jiOwLVwLhlCeER78BRJC6PmS3YpTUTm33dh A6WAsjSWpqauRXolZA+HjOymxHjBGx682MelVtek= X-Original-To: cygwin AT cygwin DOT com Delivered-To: cygwin AT cygwin DOT com DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 633FD3858CDB ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 633FD3858CDB ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1733549228; cv=none; b=wep2haLJ3Xn+T07SRNOvSwbL1SboH0zZl3IiLzKNK0f6OvbLOyYV5vKS6/VBYFWzXeidDnQSiNFKxzDrlNXJ+UrwJmaeRVMsq8m2K5iCdpNWWmB2eFoV0sDxS3t7AcDlm4GE5J1deRR6CjNHUREQIzy/9TbU6yqVTwz53s3CcWE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1733549228; c=relaxed/simple; bh=0sIbcV+Y+oZtma0Lj3R8u2ta8NFvpUcWsyoIbQCbMPU=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=toiCLIhLSA+7iyJ8WBPlfctcXHI1EK4Vg6BTwNouYGhjKNLVK94bmYR7BSmAM+lXKyAfb8uGc3EMoQCTI9p6MbRW//71YvTrM5NjMNUCMWhaP3POM1oOa9UOii//L2YUqL9YSAR38pUjwetXqc72rgcIb7GzZRIbbwk3gZtYKFk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 633FD3858CDB X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733549227; x=1734154027; h=cc:to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=a/is+LRJycuMUcgyorpJOZ5JjkT3j+5ZKLvnTizPEtk=; b=eCBdxCoYpfMTxFNN1T0rUlcLxjkgJzMRoe/MXyqzueP0lSTQhoOm6Lf4hvbdv8500J KbaYSt3YZNfd4Hm7pMG93ZPNBhm3+cOgHNsUAKB0zzeF4mQrf+Boz6R4abIuk5Mh0ykM eFYdNmWhkKv6H5dM9iOBn79vG95Cmj2Yns4rkv7pH3oYP0hTqnjaZvRDKMYousErlMPb yhlwlJM92C/RK6CQj81gR2Lu9cxQeG6pxK/wVY8SxruWGRnD+/17AaDin4HxddiIRW3l lovRyFrs+XxD2NNWURcRDya+YUq3CkCKPOTQF+e0eaAexFc6lAHE5mmcfCMlfvhL4a5P 1B2w== X-Gm-Message-State: AOJu0YxlzquryHAQjCGSkJ+T5QBeE5qeul9xCeXuUMQhamMfepFV2COd 1nGwKRdsptW5/+mUx6sFAY05gE5OLHWIpx0VlfcnCc3yglzRS9SqO4oYCG2u63Eapjk2HtfRuWT Vm2jn8y58RVROT50jYDifvfUjXWMswkAG X-Gm-Gg: ASbGncvjPlFO/uhIQfw7lPuyfA29ZXD2WDtv9OjL2ICX29rtlGcboRzUjEXOLNOsA9n LLmgvA83jQIPKAQS0eZnK5ykM0iOeFvg= X-Google-Smtp-Source: AGHT+IFONhuHX3fDyRKZQmgHaq8fdxwT14tN8NMI4N4m8JnIj04K5Zzp6vQw+N7412LBEEymTvG8f7PhfwihcWCARN0= X-Received: by 2002:a5d:64e8:0:b0:385:f5b6:9c9d with SMTP id ffacd0b85a97d-3862b39751cmr3803012f8f.33.1733549226403; Fri, 06 Dec 2024 21:27:06 -0800 (PST) MIME-Version: 1.0 Date: Fri, 6 Dec 2024 21:26:55 -0800 Message-ID: Subject: Re: Bug in handling of "1$", "2$" in printf format To: The Cygwin Mailing List Cc: Keith Thompson X-BeenThere: cygwin AT cygwin DOT com X-Mailman-Version: 2.1.30 List-Id: General Cygwin discussions and problem reports List-Archive: List-Post: List-Help: List-Subscribe: , From: Keith Thompson via Cygwin Reply-To: Keith Thompson Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "Cygwin" Brian Inglis wrote: > 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 > > 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: [SNIP] It's not always ignoring arg positions. I think there's an interaction between the "1$" / "2$" position specification and relatively complex format specifiers. The following case works correctly: $ cat c2.c #include int main(void) { int a = 42; double b = 1.0/3.0; printf("a:%2$d b:%1$g\n", b, a); printf("a:%1$d b:%2$g\n", a, b); printf("a:%d b:%g\n", a, b); } $ gcc c2.c -o c2 && ./c2 a:42 b:0.333333 a:42 b:0.333333 a:42 b:0.333333 $ (And the version of gcc shouldn't matter. printf is implemented in newlib. The code in question should be in newlib/libc/stdio/vfprintf.c.) -- 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