Re: wsprintf I64 - how to get it to include a plus sign ?
Paul <[email protected]> Thu, 8 Jan 2026 08:12:51 -0500
| Newsgroups | comp.os.ms-windows.programmer.win32,alt.comp.os.windows-xp,alt.windows7.general |
|---|---|
| Organization | A noiseless patient Spider |
| Message-ID | <[email protected]> |
On Thu, 1/8/2026 2:00 AM, R.Wieser wrote:
> Paul,
>
>> Generated 45 characters
>>
>> Pack my box with +5000000000000 liquor jugs
>
> Hmmm.... It works for you, but not for me. Did you use XP or some other,
> later version ?
>
> By the way, quite the box you have there. :-)
>
> Regards,
> Rudy Wieser
>
>
The routine you were using, was supposed to be a "legacy"
version with no floating point printout capability.
The "w" stands for "wombat" rather than "wide". That's what
a Google was telling me. So I switched to another print
variant that a couple of posts suggested would be
a successor to it.
I did my compiling in a mingw64 variant, because I wasn't sure whether
the original mingw had "c99".
If I could have copy/pasted any text examples using hex strings,
to flesh out the wide characters, I would have. But nothing
presented itself that I could copy.
The leading "+" as a sign indicator [ %+lld ], seems to work. Running
the program with a negative number, prints out a sign too.
$ ./wide
Generated 45 characters
Pack my box with -5000000000000 liquor jugs
*******
Using "history" in the terminal, it looks like the first sub-package
I populated was this one.
pacman -S mingw-w64-ucrt-x86_64-gcc
pacman -Ss gcc
So I added a couple more. These are in a way, cross compilers by
naming convention, but doing x86-to-x86 or something.
pacman -S mingw64/mingw-w64-x86_64-gcc
pacman -S mingw32/mingw-w64-i686-gcc
MINGW32 ~
$ gcc -m64 -std=c99 -o wide.exe wide.c
cc1.exe: sorry, unimplemented: 64-bit mode not compiled in
MINGW32 ~
$ gcc -m32 -std=c99 -o wide.exe wide.c
$ ./wide
Generated 18 characters
P -5000000000000
And then it doesn't work right.
MINGW64 ~
$ gcc -m64 -std=c99 -o wide.exe wide.c
MINGW64 ~
$ ./wide
Generated 18 characters
P -5000000000000
Nope. and gcc -m32 does not link there.
So whatever UCRT does, seems to work.
*******
If I take it over to the original MINGW, then only
one flavor would be supported.
gcc -std=c99 -o wide.exe wide.c
16 | int len = swprintf( buf, 100, L"%s %+lld %s", L"Pack my box with ", i, L" liquor jugs" );
| ^~~~~~~~
| snwprintf
Fixing that, gives
$ ./wide
Generated 45 characters
Pack my box with -5000000000000 liquor jugs
And the final program is:
/* #include <stdint.h> */
/* #include <inttypes.h> */
#include <stdio.h>
/* gcc -std=c99 -o wide.exe wide.c */
int main( void )
{
wchar_t buf[100];
/* int64_t i; */
long long int i;
i = -5000000000000 ;
int len = snwprintf( buf, 100, L"%s %+lld %s", L"Pack my box with ", i, L" liquor jugs" );
printf( "Generated %d characters\n\n", len );
wprintf(L"%ls\n\n", buf);
}
Paul
Paul