All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Bruce Richardson <bruce.richardson@intel.com>
Cc: Andre Muezerie <andremue@linux.microsoft.com>,
	Yipeng Wang <yipeng1.wang@intel.com>,
	Sameh Gobriel <sameh.gobriel@intel.com>,
	Vladimir Medvedkin <vladimir.medvedkin@intel.com>, <dev@dpdk.org>
Subject: Re: [PATCH] hash_readwrite_autotest: fix printf parameters
Date: Mon, 10 Mar 2025 08:36:40 -0700	[thread overview]
Message-ID: <20250310083640.46df23bb@hermes.local> (raw)
In-Reply-To: <Z87ER_iHAgTw1wuO@bricha3-mobl1.ger.corp.intel.com>

On Mon, 10 Mar 2025 10:51:51 +0000
Bruce Richardson <bruce.richardson@intel.com> wrote:

> On Fri, Mar 07, 2025 at 02:34:01PM -0800, Andre Muezerie wrote:
> > On Fri, Mar 07, 2025 at 09:01:28AM +0000, Bruce Richardson wrote:  
> > > On Thu, Mar 06, 2025 at 12:03:28PM -0800, Andre Muezerie wrote:  
> > > > Compiling with MSVC logs the warnings below, which result in
> > > > build error:
> > > > 
> > > > ../app/test/test_hash_readwrite.c(73): warning C4476: 'printf' :
> > > >     unknown type field character ''' in format specifier
> > > > ../app/test/test_hash_readwrite.c(75): warning C4474: 'printf' :
> > > >     too many arguments passed for format string
> > > > ../app/test/test_hash_readwrite.c(75): note: placeholders and
> > > >     their parameters expect 2 variadic arguments, but 4 were provided
> > > > 
> > > > Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com>
> > > > ---
> > > >  app/test/test_hash_readwrite.c | 2 +-
> > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > >   
> > > IF the "'" character is not supported, is there some other method to do
> > > thousands grouping in MSVC?
> > > 
> > > /Bruce  
> > 
> > The problem exists with all compilers I tried on Windows:
> > 
> > 1) MSVC logs the error I mentioned above
> > 
> > 2) GCC and Clang don't complain at compile time, but don't honor the "'" as a special
> > character. As an example,
> > printf("%'d\n", 1024);
> > results in
> > 'd 
> > 
> > It seems that for this syntax to work as you would expect, support needs to exist in both the
> > compiler and the libraries used.
> > 
> > Back to your question: there's no equivalent syntax on Windows that provides the thousands grouping.
> > If really needed (and I understand it is useful for large numbers), we could get the same result
> > by calling a helper function that would convert the number in the formatted string and use that
> > in the printf statement.
> > 
> > There is a Win32 API that does that. It takes a string as input though: GetNumberFormatA.
> > (https://learn.microsoft.com/en-us/windows/win32/api/winnls/nf-winnls-getnumberformata)
> > 
> > We could use ifdefs to keep the old logic on Linux and use new logic on Windows (for all compilers).
> > 
> > Let me know if this is something that would need to be done, or if the current output
> > without thousands grouping is good enough.
> > --  
> The thousands grouping is incredibly helpful when working with large
> numbers, but given the lack of support for this on Windows, we'll just have
> to go without, I think.
> 
> /Bruce

Maybe some variation of the pretty printing code that iproute2 has
(see print_num) would be useful. Feel free to reuse it.
I wrote the initial version.

  reply	other threads:[~2025-03-10 15:36 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-06 20:03 [PATCH] hash_readwrite_autotest: fix printf parameters Andre Muezerie
2025-03-07  9:01 ` Bruce Richardson
2025-03-07 22:34   ` Andre Muezerie
2025-03-10 10:51     ` Bruce Richardson
2025-03-10 15:36       ` Stephen Hemminger [this message]
2025-03-11 14:39         ` Andre Muezerie
2025-03-11 15:01           ` Morten Brørup
2025-03-11 15:33 ` [PATCH v2 1/3] eal: add function rte_size_to_str Andre Muezerie
2025-03-11 15:33   ` [PATCH v2 2/3] hash_multiwriter_autotest: fix printf parameters Andre Muezerie
2025-03-11 15:33   ` [PATCH v2 3/3] hash_readwrite_autotest: " Andre Muezerie
2025-03-11 15:49   ` [PATCH v2 1/3] eal: add function rte_size_to_str Stephen Hemminger
2025-03-11 15:51     ` Bruce Richardson
2025-03-11 16:21   ` Morten Brørup
2025-03-12 19:28 ` [PATCH v3 0/3] fix how large numbers are printed by hash tests Andre Muezerie
2025-03-12 19:28   ` [PATCH v3 1/3] eal: add function rte_size_to_str Andre Muezerie
2025-03-13  9:09     ` Bruce Richardson
2025-03-13 10:07       ` Morten Brørup
2025-03-13 10:35         ` Bruce Richardson
2025-03-14 11:56       ` Mattias Rönnblom
2025-03-13 10:41     ` Bruce Richardson
2025-03-13 14:06       ` Andre Muezerie
2025-03-12 19:28   ` [PATCH v3 2/3] hash_multiwriter_autotest: fix printf parameters Andre Muezerie
2025-03-12 19:28   ` [PATCH v3 3/3] hash_readwrite_autotest: " Andre Muezerie
2025-03-13 16:51 ` [PATCH v4 0/3] fix how large numbers are printed by hash tests Andre Muezerie
2025-03-13 16:51   ` [PATCH v4 1/3] eal: add function rte_size_to_str Andre Muezerie
2025-03-13 16:59     ` Morten Brørup
2025-03-13 16:51   ` [PATCH v4 2/3] hash_multiwriter_autotest: fix printf parameters Andre Muezerie
2025-03-13 16:51   ` [PATCH v4 3/3] hash_readwrite_autotest: " Andre Muezerie
2025-03-13 17:33   ` [PATCH v4 0/3] fix how large numbers are printed by hash tests Bruce Richardson
2025-04-09  1:20 ` [PATCH v5 " Andre Muezerie
2025-04-09  1:20   ` [PATCH v5 1/3] eal: add function rte_size_to_str Andre Muezerie
2025-04-09  1:20   ` [PATCH v5 2/3] hash_multiwriter_autotest: fix printf parameters Andre Muezerie
2025-04-09  1:20   ` [PATCH v5 3/3] hash_readwrite_autotest: " Andre Muezerie
2025-04-10 11:34   ` [PATCH v5 0/3] fix how large numbers are printed by hash tests David Marchand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250310083640.46df23bb@hermes.local \
    --to=stephen@networkplumber.org \
    --cc=andremue@linux.microsoft.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=sameh.gobriel@intel.com \
    --cc=vladimir.medvedkin@intel.com \
    --cc=yipeng1.wang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.