DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] hash_readwrite_autotest: fix printf parameters
@ 2025-03-06 20:03 Andre Muezerie
  2025-03-07  9:01 ` Bruce Richardson
  0 siblings, 1 reply; 3+ messages in thread
From: Andre Muezerie @ 2025-03-06 20:03 UTC (permalink / raw)
  To: Yipeng Wang, Sameh Gobriel, Bruce Richardson, Vladimir Medvedkin
  Cc: dev, Andre Muezerie

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(-)

diff --git a/app/test/test_hash_readwrite.c b/app/test/test_hash_readwrite.c
index 1867376ade..dc07df709a 100644
--- a/app/test/test_hash_readwrite.c
+++ b/app/test/test_hash_readwrite.c
@@ -70,7 +70,7 @@ test_hash_readwrite_worker(__rte_unused void *arg)
 	}
 	offset = tbl_rw_test_param.num_insert * i;
 
-	printf("Core #%d inserting and reading %d: %'"PRId64" - %'"PRId64"\n",
+	printf("Core #%d inserting and reading %d: %" PRId64 " - %" PRId64 "\n",
 	       lcore_id, tbl_rw_test_param.num_insert,
 	       offset, offset + tbl_rw_test_param.num_insert - 1);
 
-- 
2.48.1.vfs.0.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] hash_readwrite_autotest: fix printf parameters
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Bruce Richardson @ 2025-03-07  9:01 UTC (permalink / raw)
  To: Andre Muezerie; +Cc: Yipeng Wang, Sameh Gobriel, Vladimir Medvedkin, dev

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] hash_readwrite_autotest: fix printf parameters
  2025-03-07  9:01 ` Bruce Richardson
@ 2025-03-07 22:34   ` Andre Muezerie
  0 siblings, 0 replies; 3+ messages in thread
From: Andre Muezerie @ 2025-03-07 22:34 UTC (permalink / raw)
  To: Bruce Richardson; +Cc: Yipeng Wang, Sameh Gobriel, Vladimir Medvedkin, dev

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.
--
Andre Muezerie

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-03-07 22:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).