Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Nuclear war would really set back cable." -- Ted Turner


devel / comp.lang.c / Re: #include <stdint.h>

SubjectAuthor
* #include <stdint.h>SIMON
+* Re: #include <stdint.h>Bart
|`* Re: #include <stdint.h>Bart
| `* Re: #include <stdint.h>Philipp Klaus Krause
|  +* Re: #include <stdint.h>Keith Thompson
|  |`- Re: #include <stdint.h>Philipp Klaus Krause
|  `- Re: #include <stdint.h>Bart
+- Re: #include <stdint.h>James Kuyper
+- Re: #include <stdint.h>Ben Bacarisse
`* Re: #include <stdint.h>Keith Thompson
 +* Re: #include <stdint.h>Philipp Klaus Krause
 |`* Re: #include <stdint.h>Keith Thompson
 | `- Re: #include <stdint.h>Philipp Klaus Krause
 `* Re: #include <stdint.h>Tim Rentsch
  +* Re: #include <stdint.h>Keith Thompson
  |+* Re: #include <stdint.h>Tim Rentsch
  ||`* Re: #include <stdint.h>Keith Thompson
  || `* Re: #include <stdint.h>Tim Rentsch
  ||  `* Re: #include <stdint.h>Keith Thompson
  ||   `* Re: #include <stdint.h>Tim Rentsch
  ||    `* Re: #include <stdint.h>Keith Thompson
  ||     `* Re: #include <stdint.h>Tim Rentsch
  ||      +- Re: #include <stdint.h>Keith Thompson
  ||      `- Re: #include <stdint.h>James Kuyper
  |`* Re: #include <stdint.h>Andrey Tarasevich
  | +- Re: #include <stdint.h>Keith Thompson
  | `* Re: #include <stdint.h>James Kuyper
  |  `* Re: #include <stdint.h>Branimir Maksimovic
  |   `* Re: #include <stdint.h>James Kuyper
  |    `- Re: #include <stdint.h>Branimir Maksimovic
  `* Re: #include <stdint.h>Ben Bacarisse
   +* Re: #include <stdint.h>Öö Tiib
   |`- Re: #include <stdint.h>Keith Thompson
   `- Re: #include <stdint.h>Tim Rentsch

Pages:12
#include <stdint.h>

<sa5vrs$7d3$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17012&group=comp.lang.c#17012

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: inva...@invalid.invalid (SIMON)
Newsgroups: comp.lang.c
Subject: #include <stdint.h>
Date: Sun, 13 Jun 2021 23:08:34 +0100
Organization: Aioe.org NNTP Server
Lines: 32
Message-ID: <sa5vrs$7d3$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 13 Jun 2021 22:12:12 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="3ace9f91cf5427d24a76d8d04b06c26c";
logging-data="7587"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX184zWCjloU9etilor12nuynuK++46CSNLM="
Cancel-Lock: sha1:pb26CrWQCvluIXVfzjBUVLQIM1M=
Content-Language: en-GB
 by: SIMON - Sun, 13 Jun 2021 22:08 UTC

What changes do I need to make to get the correct values for the last
two items in this program:

> #include <stdio.h>
> #include <stdint.h>
> #include <limits.h>
>
> int main()
> {
> printf("INT_MAX : %d\n", INT_MAX);
> printf("INT_MIN : %d\n", INT_MIN);
> printf("LONG_MAX : %ld\n", (long)LONG_MAX);
> printf("LONG_MIN : %ld\n", (long)LONG_MIN);
> printf("UINT_MAX : %u\n", (unsigned int)UINT_MAX);
> printf("ULONG_MAX : %lu\n", (unsigned long)ULONG_MAX);
> printf("USHRT_MAX : %d\n", (unsigned short)USHRT_MAX);
> printf("\nFrom stdint.h: \n");
> printf("INT8_MAX : %d\n", INT8_MAX);
> printf("INT16_MAX : %d\n", INT16_MAX);
> printf("INT32_MAX : %d\n", INT32_MAX);
> printf("INT64_MAX : %lld\n", INT64_MAX);
> printf("UINT8_MAX : %d\n", UINT16_MAX);
> printf("UINT16_MAX : %d\n", UINT16_MAX);
> printf("UINT32_MAX : %d\n", UINT32_MAX);
> printf("UINT64_MAX : %lld\n", UINT64_MAX);
> }

I am using Windows 10 64 bit machine and I have tried GCC64 bit and
Visual Studio 2019 64 bit. The last two results are just ( -1 ). this is clearly over/underflow somehow so what changes are necessary.

I was in the opinion that stdint.h is cross-compiler/cross- platform
compliant.

Re: #include <stdint.h>

<GDvxI.19645$R591.15186@fx37.ams4>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17013&group=comp.lang.c#17013

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx37.ams4.POSTED!not-for-mail
Subject: Re: #include <stdint.h>
Newsgroups: comp.lang.c
References: <sa5vrs$7d3$1@dont-email.me>
From: bc...@freeuk.com (Bart)
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
MIME-Version: 1.0
In-Reply-To: <sa5vrs$7d3$1@dont-email.me>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-GB
Content-Transfer-Encoding: 8bit
X-Antivirus: AVG (VPS 210613-4, 13/06/2021), Outbound message
X-Antivirus-Status: Clean
Lines: 37
Message-ID: <GDvxI.19645$R591.15186@fx37.ams4>
X-Complaints-To: http://netreport.virginmedia.com
NNTP-Posting-Date: Sun, 13 Jun 2021 22:27:50 UTC
Organization: virginmedia.com
Date: Sun, 13 Jun 2021 23:27:48 +0100
X-Received-Bytes: 2215
 by: Bart - Sun, 13 Jun 2021 22:27 UTC

On 13/06/2021 23:08, SIMON wrote:
> What changes do I need to make to get the correct values for the last
> two items in this program:
>
>> #include <stdio.h>
>> #include <stdint.h>
>> #include <limits.h>
>>
>> int main()
>> {
>>  printf("INT_MAX : %d\n", INT_MAX);
>>  printf("INT_MIN : %d\n", INT_MIN);
>>  printf("LONG_MAX : %ld\n", (long)LONG_MAX);
>>  printf("LONG_MIN : %ld\n", (long)LONG_MIN);
>>  printf("UINT_MAX : %u\n", (unsigned int)UINT_MAX);
>>  printf("ULONG_MAX : %lu\n", (unsigned long)ULONG_MAX);
>>  printf("USHRT_MAX : %d\n", (unsigned short)USHRT_MAX);
>>  printf("\nFrom stdint.h: \n");
>>  printf("INT8_MAX : %d\n", INT8_MAX);
>>  printf("INT16_MAX : %d\n", INT16_MAX);
>>  printf("INT32_MAX : %d\n", INT32_MAX);
>>  printf("INT64_MAX : %lld\n", INT64_MAX);
>>  printf("UINT8_MAX : %d\n", UINT16_MAX);
>>  printf("UINT16_MAX : %d\n", UINT16_MAX);
>>  printf("UINT32_MAX : %d\n", UINT32_MAX);
>>  printf("UINT64_MAX : %lld\n", UINT64_MAX);
>> }
>
> I am using Windows 10 64 bit machine and I have tried GCC64 bit and
> Visual Studio 2019 64 bit. The last two results are just ( -1 ). this is
> clearly over/underflow somehow so what changes are necessary.
>
> I was in the opinion that stdint.h is cross-compiler/cross- platform
> compliant.

Try %ud and %ulld.

Re: #include <stdint.h>

<sa615b$e1r$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17014&group=comp.lang.c#17014

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c
Subject: Re: #include <stdint.h>
Date: Sun, 13 Jun 2021 18:34:18 -0400
Organization: A noiseless patient Spider
Lines: 71
Message-ID: <sa615b$e1r$1@dont-email.me>
References: <sa5vrs$7d3$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 13 Jun 2021 22:34:19 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="f7fb7d9b87b39bcf8ee4283023236ae8";
logging-data="14395"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/v7E0eR62oO59c9gDUMQNXKuCJ6IMBoGc="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.8.1
Cancel-Lock: sha1:7RjpHXL165yv6LbtgJq29XfD4xU=
In-Reply-To: <sa5vrs$7d3$1@dont-email.me>
Content-Language: en-US
 by: James Kuyper - Sun, 13 Jun 2021 22:34 UTC

On 6/13/21 6:08 PM, SIMON wrote:
> What changes do I need to make to get the correct values for the last
> two items in this program:
>
>> #include <stdio.h>
>> #include <stdint.h>
>> #include <limits.h>

#include <inttypes.h>

>> int main()
>> {
>> printf("INT_MAX : %d\n", INT_MAX);
>> printf("INT_MIN : %d\n", INT_MIN);
>> printf("LONG_MAX : %ld\n", (long)LONG_MAX);
>> printf("LONG_MIN : %ld\n", (long)LONG_MIN);
>> printf("UINT_MAX : %u\n", (unsigned int)UINT_MAX);
>> printf("ULONG_MAX : %lu\n", (unsigned long)ULONG_MAX);
>> printf("USHRT_MAX : %d\n", (unsigned short)USHRT_MAX);
>> printf("\nFrom stdint.h: \n");
>> printf("INT8_MAX : %d\n", INT8_MAX);
>> printf("INT16_MAX : %d\n", INT16_MAX);
>> printf("INT32_MAX : %d\n", INT32_MAX);
>> printf("INT64_MAX : %lld\n", INT64_MAX);
>> printf("UINT8_MAX : %d\n", UINT16_MAX);
>> printf("UINT16_MAX : %d\n", UINT16_MAX);
>> printf("UINT32_MAX : %d\n", UINT32_MAX);
>> printf("UINT64_MAX : %lld\n", UINT64_MAX);

You should not be using the "d" conversion specifier for unsigned types.
You should use "u", "o", "x" or "X" formats.
In general, you should not use explicit length specifiers (such as "h",
"hh", "l", and "ll") for the size-named types - there's no guaranteed
connection between the specifiers and the types. Instead, you should use
the print format macros from <inttypes.h>:

printf("INT8_MAX : %" PRId8 "\n", INT8_MAX);
printf("INT8_MAX : %" PRId16 "\n", INT16_MAX);
printf("INT8_MAX : %" PRId32 "\n", INT32_MAX);
printf("INT8_MAX : %" PRId64 "\n", INT64_MAX);

Assuming that you would actually have chosen the "u" conversion
specifier, you should use the following for the unsigned types. If you
would prefer, for instance, the "x" conversion specifier, change "u" to
"x" in the following macro names:
printf("UINT8_MAX : %" PRIu8 "\n", UINT8_MAX);
printf("UINT8_MAX : %" PRIu16 "\n", UINT16_MAX);
printf("UINT8_MAX : %" PRIu32 "\n", UINT32_MAX);
printf("UINT8_MAX : %" PRIu64 "\n", UINT64_MAX);

>> }
>
> I am using Windows 10 64 bit machine and I have tried GCC64 bit and
> Visual Studio 2019 64 bit. The last two results are just ( -1 ). this is clearly over/underflow somehow so what changes are necessary.
>
> I was in the opinion that stdint.h is cross-compiler/cross- platform
> compliant.

It is, when used correctly - which means, among other things, using the
print macros rather than explicit length specifiers in printf/scanf
family format strings. The exact-sized types are optional, but the
corresponding macros must be #defined and if (and only if) the
corresponding types are supported.
For maximum portability, you should avoid the exact-sized types and use
only int_fastN_t and int_leastN_t types, and only for the values of N
for which support for those types is mandatory: 8, 16, 32, and 64. In
practice, most people can ignore this advice.

Re: #include <stdint.h>

<87h7i11jhx.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17015&group=comp.lang.c#17015

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: #include <stdint.h>
Date: Sun, 13 Jun 2021 23:34:50 +0100
Organization: A noiseless patient Spider
Lines: 55
Message-ID: <87h7i11jhx.fsf@bsb.me.uk>
References: <sa5vrs$7d3$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="316c17f194a316eab4581e413f6701b5";
logging-data="9266"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+lFc5miMG8DxhIU9zH3UAqHXkRDRcc+OE="
Cancel-Lock: sha1:ZQ/+WG9f0d8ORcTfE9opXX89N1s=
sha1:dLfUIPgw8k6bwvMCLKlIb4SLij8=
X-BSB-Auth: 1.d51473d2c393866c5b0c.20210613233450BST.87h7i11jhx.fsf@bsb.me.uk
 by: Ben Bacarisse - Sun, 13 Jun 2021 22:34 UTC

SIMON <invalid@invalid.invalid> writes:

> What changes do I need to make to get the correct values for the last
> two items in this program:
>
>> #include <stdio.h>
>> #include <stdint.h>
>> #include <limits.h>
>>
>> int main()
>> {
>> printf("INT_MAX : %d\n", INT_MAX);
>> printf("INT_MIN : %d\n", INT_MIN);
>> printf("LONG_MAX : %ld\n", (long)LONG_MAX);
>> printf("LONG_MIN : %ld\n", (long)LONG_MIN);
>> printf("UINT_MAX : %u\n", (unsigned int)UINT_MAX);
>> printf("ULONG_MAX : %lu\n", (unsigned long)ULONG_MAX);
>> printf("USHRT_MAX : %d\n", (unsigned short)USHRT_MAX);

None of these casts add anything.

(There are also LLONG_MIN/MAX and ULLONG_MAX which you can print using
%lld and %llu.)

>> printf("\nFrom stdint.h: \n");
>> printf("INT8_MAX : %d\n", INT8_MAX);
>> printf("INT16_MAX : %d\n", INT16_MAX);
>> printf("INT32_MAX : %d\n", INT32_MAX);
>> printf("INT64_MAX : %lld\n", INT64_MAX);
>> printf("UINT8_MAX : %d\n", UINT16_MAX);
>> printf("UINT16_MAX : %d\n", UINT16_MAX);
>> printf("UINT32_MAX : %d\n", UINT32_MAX);
>> printf("UINT64_MAX : %lld\n", UINT64_MAX);

All of these types have macros defined in inttypes.h that can be used to
print them. For example

printf("UINT64_MAX : %"PRIu64"\n", UINT64_MAX);

For maximum portability, you can't even assume that %d can be used for
INT32_MAX -- on a system where int is narrower than 32 bits, %d won't
work. Similarly, %d won't necessarily work even for UINT16_MAX. On a
system with a 16-bit int you would have to use %u. But all of these are
"fudges" to some extent.

The last two can be also fudged (for the sort of system you are likely
to be using) like this:

printf("UINT32_MAX : %u\n", UINT32_MAX);
printf("UINT64_MAX : %llu\n", UINT64_MAX);

but really, why fudge it? Use PRIu32 and PRIu64.

--
Ben.

Re: #include <stdint.h>

<v3wxI.85192$_jR.41980@fx14.ams4>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17016&group=comp.lang.c#17016

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!paganini.bofh.team!news.dns-netz.com!news.freedyn.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx14.ams4.POSTED!not-for-mail
Subject: Re: #include <stdint.h>
Newsgroups: comp.lang.c
References: <sa5vrs$7d3$1@dont-email.me> <GDvxI.19645$R591.15186@fx37.ams4>
From: bc...@freeuk.com (Bart)
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
MIME-Version: 1.0
In-Reply-To: <GDvxI.19645$R591.15186@fx37.ams4>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-GB
Content-Transfer-Encoding: 8bit
X-Antivirus: AVG (VPS 210613-4, 13/06/2021), Outbound message
X-Antivirus-Status: Clean
Lines: 50
Message-ID: <v3wxI.85192$_jR.41980@fx14.ams4>
X-Complaints-To: http://netreport.virginmedia.com
NNTP-Posting-Date: Sun, 13 Jun 2021 22:57:31 UTC
Organization: virginmedia.com
Date: Sun, 13 Jun 2021 23:57:29 +0100
X-Received-Bytes: 2716
 by: Bart - Sun, 13 Jun 2021 22:57 UTC

On 13/06/2021 23:27, Bart wrote:
> On 13/06/2021 23:08, SIMON wrote:
>> What changes do I need to make to get the correct values for the last
>> two items in this program:
>>
>>> #include <stdio.h>
>>> #include <stdint.h>
>>> #include <limits.h>
>>>
>>> int main()
>>> {
>>>  printf("INT_MAX : %d\n", INT_MAX);
>>>  printf("INT_MIN : %d\n", INT_MIN);
>>>  printf("LONG_MAX : %ld\n", (long)LONG_MAX);
>>>  printf("LONG_MIN : %ld\n", (long)LONG_MIN);
>>>  printf("UINT_MAX : %u\n", (unsigned int)UINT_MAX);
>>>  printf("ULONG_MAX : %lu\n", (unsigned long)ULONG_MAX);
>>>  printf("USHRT_MAX : %d\n", (unsigned short)USHRT_MAX);
>>>  printf("\nFrom stdint.h: \n");
>>>  printf("INT8_MAX : %d\n", INT8_MAX);
>>>  printf("INT16_MAX : %d\n", INT16_MAX);
>>>  printf("INT32_MAX : %d\n", INT32_MAX);
>>>  printf("INT64_MAX : %lld\n", INT64_MAX);
>>>  printf("UINT8_MAX : %d\n", UINT16_MAX);
>>>  printf("UINT16_MAX : %d\n", UINT16_MAX);
>>>  printf("UINT32_MAX : %d\n", UINT32_MAX);
>>>  printf("UINT64_MAX : %lld\n", UINT64_MAX);
>>> }
>>
>> I am using Windows 10 64 bit machine and I have tried GCC64 bit and
>> Visual Studio 2019 64 bit. The last two results are just ( -1 ). this
>> is clearly over/underflow somehow so what changes are necessary.
>>
>> I was in the opinion that stdint.h is cross-compiler/cross- platform
>> compliant.
>
>
> Try %ud and %ulld.

Huh. They should be %u and %llu (u is because they are unsigned).

Or you can display as hex using %X and $llX.

This should fine if running under Windows. For portable code, you really
need to use an ugly set of macros from stdint.h or inttypes.h, since the
correct formats vary betweeen Windows and Linux (eg. Linux might need
one 'l' rather than two, but I believe 'll' will work too).

If you just want to know the limits, you can also look inside stdint.h.

Re: #include <stdint.h>

<87wnqxxoe3.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17017&group=comp.lang.c#17017

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: #include <stdint.h>
Date: Sun, 13 Jun 2021 17:48:04 -0700
Organization: None to speak of
Lines: 118
Message-ID: <87wnqxxoe3.fsf@nosuchdomain.example.com>
References: <sa5vrs$7d3$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="424da5ba9f7e7fcac70b5d6e5f55a732";
logging-data="21402"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19kL8p5kcrBiPwbpk1smxZW"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:eiRNwkImgsr2OxAzXWcBJLSlnko=
sha1:e+aPDdteu4U/4FnXIx7Dgg32bFU=
 by: Keith Thompson - Mon, 14 Jun 2021 00:48 UTC

SIMON <invalid@invalid.invalid> writes:
> What changes do I need to make to get the correct values for the last
> two items in this program:
>
>> #include <stdio.h>
>> #include <stdint.h>
>> #include <limits.h>
>>
>> int main()
>> {
>> printf("INT_MAX : %d\n", INT_MAX);
>> printf("INT_MIN : %d\n", INT_MIN);
>> printf("LONG_MAX : %ld\n", (long)LONG_MAX);
>> printf("LONG_MIN : %ld\n", (long)LONG_MIN);
>> printf("UINT_MAX : %u\n", (unsigned int)UINT_MAX);
>> printf("ULONG_MAX : %lu\n", (unsigned long)ULONG_MAX);
>> printf("USHRT_MAX : %d\n", (unsigned short)USHRT_MAX);
>> printf("\nFrom stdint.h: \n");
>> printf("INT8_MAX : %d\n", INT8_MAX);
>> printf("INT16_MAX : %d\n", INT16_MAX);
>> printf("INT32_MAX : %d\n", INT32_MAX);
>> printf("INT64_MAX : %lld\n", INT64_MAX);
>> printf("UINT8_MAX : %d\n", UINT16_MAX);
>> printf("UINT16_MAX : %d\n", UINT16_MAX);
>> printf("UINT32_MAX : %d\n", UINT32_MAX);
>> printf("UINT64_MAX : %lld\n", UINT64_MAX);
>> }
>
> I am using Windows 10 64 bit machine and I have tried GCC64 bit and
> Visual Studio 2019 64 bit. The last two results are just ( -1 ). this
> is clearly over/underflow somehow so what changes are necessary.
>
> I was in the opinion that stdint.h is cross-compiler/cross- platform
> compliant.

It is -- but none of the exact-width types are guaranteed to exist
(though the 8, 16, 32, and 64 bit ones almost certainly will on typical
systems).

<inttypes.h> provides macros that expand to appropriate format strings.
<inttypes.h> includes <stdint.h>, so you don't need to include both,
though you can.

Using the macros:

#include <stdio.h>
// #include <stdint.h>
#include <inttypes.h>
#include <limits.h>

int main(void) {
printf("INT_MAX : %d\n", INT_MAX);
printf("INT_MIN : %d\n", INT_MIN);
printf("LONG_MAX : %ld\n", LONG_MAX);
printf("LONG_MIN : %ld\n", LONG_MIN);
printf("UINT_MAX : %u\n", UINT_MAX);
printf("ULONG_MAX : %lu\n", ULONG_MAX);
printf("USHRT_MAX : %u\n", (unsigned)USHRT_MAX);
printf("\nFrom stdint.h: \n");
printf("INT8_MAX : %" PRId8 "\n", INT8_MAX);
printf("INT16_MAX : %" PRId16 "\n", INT16_MAX);
printf("INT32_MAX : %" PRId32 "\n", INT32_MAX);
printf("INT64_MAX : %" PRId64 "\n", INT64_MAX);
printf("UINT8_MAX : %" PRIu8 "\n", UINT16_MAX);
printf("UINT16_MAX : %" PRIu16 "\n", UINT16_MAX);
printf("UINT32_MAX : %" PRIu32 "\n", UINT32_MAX);
printf("UINT64_MAX : %" PRIu64 "\n", UINT64_MAX);
}

Most of the casts in your original program are unnecessary, since the
expressions are already of the type you were casting them to. But
unsigned short could promote either to signed int or to unsigned int,
depending on their ranges, so converting to unsigned and using "%u" is
appropriate. In general, when passed to a variadic function like
printf, an argument of an integer type narrower than int is promoted to
int if type's range fits in int, to unsigned int otherwise.

An alternative, if you don't want to remember or look up all those
macros, is to convert to a type that's known to be wide enough.
long long is guaranteed to be at least 64 bits (and is almost always
exactly 64 bits), so this might be simpler:

#include <stdio.h>
#include <stdint.h>
#include <limits.h>

int main(void) {
printf("INT_MAX : %d\n", INT_MAX);
printf("INT_MIN : %d\n", INT_MIN);
printf("LONG_MAX : %ld\n", LONG_MAX);
printf("LONG_MIN : %ld\n", LONG_MIN);
printf("UINT_MAX : %u\n", UINT_MAX);
printf("ULONG_MAX : %lu\n", ULONG_MAX);
printf("USHRT_MAX : %u\n", (unsigned)USHRT_MAX);
printf("\nFrom stdint.h : \n");
printf("INT8_MAX : %lld\n", (long long)INT8_MAX);
printf("INT16_MAX : %lld\n", (long long)INT16_MAX);
printf("INT32_MAX : %lld\n", (long long)INT32_MAX);
printf("INT64_MAX : %lld\n", (long long)INT64_MAX);
printf("UINT8_MAX : %llu\n", (unsigned long long)UINT16_MAX);
printf("UINT16_MAX : %llu\n", (unsigned long long)UINT16_MAX);
printf("UINT32_MAX : %llu\n", (unsigned long long)UINT32_MAX);
printf("UINT64_MAX : %llu\n", (unsigned long long)UINT64_MAX);
}

There's some performance cost relative to the type-specific format
macros, but printf itself is far more expensive than a few integer type
conversions.

If you have an integer type that might possibly be wider than long
long (which is unlikely in practice), you can convert to intmax_t
or uintmax_t and use "%jd" or "%ju". That might be overkill if you
don't really need 100% guarantee portability.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */

Re: #include <stdint.h>

<sa6v0v$4r0$1@solani.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17020&group=comp.lang.c#17020

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!feeder5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From: pkk...@spth.de (Philipp Klaus Krause)
Newsgroups: comp.lang.c
Subject: Re: #include <stdint.h>
Date: Mon, 14 Jun 2021 09:03:59 +0200
Message-ID: <sa6v0v$4r0$1@solani.org>
References: <sa5vrs$7d3$1@dont-email.me> <GDvxI.19645$R591.15186@fx37.ams4>
<v3wxI.85192$_jR.41980@fx14.ams4>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 14 Jun 2021 07:03:59 -0000 (UTC)
Injection-Info: solani.org;
logging-data="4960"; mail-complaints-to="abuse@news.solani.org"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.10.0
Content-Language: en-US
In-Reply-To: <v3wxI.85192$_jR.41980@fx14.ams4>
X-User-ID: eJwFwQkBACAIA8BKfBsaBxH7R/AOTmVnEAw8vKpkQ7vduWR7Tq+5brZFlXZT43SCBZkjUh8RTxCM
Cancel-Lock: sha1:HXVVYlNpPh0v+xPGZ60hTCgXKHY=
 by: Philipp Klaus Krause - Mon, 14 Jun 2021 07:03 UTC

Am 14.06.21 um 00:57 schrieb Bart:
>
> This should fine if running under Windows. For portable code, you really
> need to use an ugly set of macros from stdint.h or inttypes.h, since the
> correct formats vary betweeen Windows and Linux (eg. Linux might need
> one 'l' rather than two, but I believe 'll' will work too).

The C23 standard from 2023 has the %w modifier:

printf("UINT64_MAX : %w64u\n", UINT64_MAX);

Philipp

Re: #include <stdint.h>

<sa6vaf$4r0$2@solani.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17021&group=comp.lang.c#17021

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!feeder5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From: pkk...@spth.de (Philipp Klaus Krause)
Newsgroups: comp.lang.c
Subject: Re: #include <stdint.h>
Date: Mon, 14 Jun 2021 09:09:03 +0200
Message-ID: <sa6vaf$4r0$2@solani.org>
References: <sa5vrs$7d3$1@dont-email.me>
<87wnqxxoe3.fsf@nosuchdomain.example.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 14 Jun 2021 07:09:03 -0000 (UTC)
Injection-Info: solani.org;
logging-data="4960"; mail-complaints-to="abuse@news.solani.org"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.10.0
In-Reply-To: <87wnqxxoe3.fsf@nosuchdomain.example.com>
Content-Language: en-US
Cancel-Lock: sha1:vnM64kKfTbw4DrWsFPt1yHWj+/A=
X-User-ID: eJwFwYkBADAEA8CVigjG6cP+I/TOjcIboBM+Pra08uyK27UHWd5N9HOLRRwBgkq1i7anKR8RqRBT
 by: Philipp Klaus Krause - Mon, 14 Jun 2021 07:09 UTC

Am 14.06.21 um 02:48 schrieb Keith Thompson:
>
> If you have an integer type that might possibly be wider than long
> long (which is unlikely in practice), you can convert to intmax_t
> or uintmax_t and use "%jd" or "%ju". That might be overkill if you
> don't really need 100% guarantee portability.
>

And there is the real risk of intmax_t being removed from a future
standard, which is very, very unlikely to ever happen to long long.

Philipp

Re: #include <stdint.h>

<87sg1kyhv7.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17022&group=comp.lang.c#17022

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: #include <stdint.h>
Date: Mon, 14 Jun 2021 01:23:40 -0700
Organization: None to speak of
Lines: 18
Message-ID: <87sg1kyhv7.fsf@nosuchdomain.example.com>
References: <sa5vrs$7d3$1@dont-email.me> <GDvxI.19645$R591.15186@fx37.ams4>
<v3wxI.85192$_jR.41980@fx14.ams4> <sa6v0v$4r0$1@solani.org>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="424da5ba9f7e7fcac70b5d6e5f55a732";
logging-data="24087"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+XpKwgVUJ7ru3UTZh/l0uK"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:xi0vfwvN35FKInokkMmyyq5zfPU=
sha1:XZC0PyfE7snollIQIgiTCZFboTE=
 by: Keith Thompson - Mon, 14 Jun 2021 08:23 UTC

Philipp Klaus Krause <pkk@spth.de> writes:
> Am 14.06.21 um 00:57 schrieb Bart:
>> This should fine if running under Windows. For portable code, you really
>> need to use an ugly set of macros from stdint.h or inttypes.h, since the
>> correct formats vary betweeen Windows and Linux (eg. Linux might need
>> one 'l' rather than two, but I believe 'll' will work too).
>
> The C23 standard from 2023 has the %w modifier:
>
> printf("UINT64_MAX : %w64u\n", UINT64_MAX);

Do you have a source for that? The latest draft I have (N2596,
Dec 11 2020) doesn't mention that.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */

Re: #include <stdint.h>

<87o8c8yhtx.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17023&group=comp.lang.c#17023

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: #include <stdint.h>
Date: Mon, 14 Jun 2021 01:24:26 -0700
Organization: None to speak of
Lines: 17
Message-ID: <87o8c8yhtx.fsf@nosuchdomain.example.com>
References: <sa5vrs$7d3$1@dont-email.me>
<87wnqxxoe3.fsf@nosuchdomain.example.com> <sa6vaf$4r0$2@solani.org>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="424da5ba9f7e7fcac70b5d6e5f55a732";
logging-data="24087"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/N2z9rWywba4qFjH3OpuDN"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:Fd5PKJzTsgwM8Vd1KNcWnTlY70U=
sha1:T/883uMTu7da2clTyPUHrNpWWhc=
 by: Keith Thompson - Mon, 14 Jun 2021 08:24 UTC

Philipp Klaus Krause <pkk@spth.de> writes:
> Am 14.06.21 um 02:48 schrieb Keith Thompson:
>> If you have an integer type that might possibly be wider than long
>> long (which is unlikely in practice), you can convert to intmax_t
>> or uintmax_t and use "%jd" or "%ju". That might be overkill if you
>> don't really need 100% guarantee portability.
>
> And there is the real risk of intmax_t being removed from a future
> standard, which is very, very unlikely to ever happen to long long.

I doubt that there's much risk of that. I can imagine its semantics
being changed, but removing it would break existing code.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */

Re: #include <stdint.h>

<sa7b4i$b7n$1@solani.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17024&group=comp.lang.c#17024

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!feeder5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From: pkk...@spth.de (Philipp Klaus Krause)
Newsgroups: comp.lang.c
Subject: Re: #include <stdint.h>
Date: Mon, 14 Jun 2021 12:30:42 +0200
Message-ID: <sa7b4i$b7n$1@solani.org>
References: <sa5vrs$7d3$1@dont-email.me>
<87wnqxxoe3.fsf@nosuchdomain.example.com> <sa6vaf$4r0$2@solani.org>
<87o8c8yhtx.fsf@nosuchdomain.example.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 14 Jun 2021 10:30:42 -0000 (UTC)
Injection-Info: solani.org;
logging-data="11511"; mail-complaints-to="abuse@news.solani.org"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Content-Language: en-US
In-Reply-To: <87o8c8yhtx.fsf@nosuchdomain.example.com>
X-User-ID: eJwNycEBwCAIA8CVQAnBcQRh/xHa+x62qxfN4YbBeNyTAr632LVn0ZBo0ujgoVgiVPsfkbrxAQ5kEFE=
Cancel-Lock: sha1:9wI4gowtyh5bEGTjXg8/AIddtbM=
 by: Philipp Klaus Krause - Mon, 14 Jun 2021 10:30 UTC

>> And there is the real risk of intmax_t being removed from a future
>> standard, which is very, very unlikely to ever happen to long long.
>
> I doubt that there's much risk of that. I can imagine its semantics
> being changed, but removing it would break existing code.
>

The problem with intmax_t:
It needs to be the widest type, so it needs to grow when y type is
added. That breaks the ABI.
There was a WG14 straw poll opting for full removal, but no wording had
been proposed at that time, and no wording has come up so far. However,
N2548 has changed some functions to use different types instead:
Functions new in C23 have been changed to use whatever other type was
most appropriate. Older functions have been changed to long long, since
apparently practically intmax_t was the same as long long, so this
change preserves the ABI.

Philipp

Re: #include <stdint.h>

<sa7b6a$b7n$2@solani.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17025&group=comp.lang.c#17025

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!feeder5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From: pkk...@spth.de (Philipp Klaus Krause)
Newsgroups: comp.lang.c
Subject: Re: #include <stdint.h>
Date: Mon, 14 Jun 2021 12:31:38 +0200
Message-ID: <sa7b6a$b7n$2@solani.org>
References: <sa5vrs$7d3$1@dont-email.me> <GDvxI.19645$R591.15186@fx37.ams4>
<v3wxI.85192$_jR.41980@fx14.ams4> <sa6v0v$4r0$1@solani.org>
<87sg1kyhv7.fsf@nosuchdomain.example.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 14 Jun 2021 10:31:38 -0000 (UTC)
Injection-Info: solani.org;
logging-data="11511"; mail-complaints-to="abuse@news.solani.org"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
X-User-ID: eJwFwQERACAIA8BKKGyccRBZ/wj+w7nYGQQDghb21Qm+M7DJ52aVbavlWy9KHXWHU3OZLXwj7BIY
Content-Language: en-US
In-Reply-To: <87sg1kyhv7.fsf@nosuchdomain.example.com>
Cancel-Lock: sha1:B99sl09FtDfBotV/5GyMSqaKi9E=
 by: Philipp Klaus Krause - Mon, 14 Jun 2021 10:31 UTC

>> The C23 standard from 2023 has the %w modifier:
>>
>> printf("UINT64_MAX : %w64u\n", UINT64_MAX);
>
> Do you have a source for that? The latest draft I have (N2596,
> Dec 11 2020) doesn't mention that.

The proposal was N2680, which according to the meeting minutes N2690 is in.

Philipp

Re: #include <stdint.h>

<aAGxI.151628$co68.48603@fx03.ams4>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17026&group=comp.lang.c#17026

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!paganini.bofh.team!news.dns-netz.com!news.freedyn.net!newsreader4.netcologne.de!news.netcologne.de!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx03.ams4.POSTED!not-for-mail
Subject: Re: #include <stdint.h>
Newsgroups: comp.lang.c
References: <sa5vrs$7d3$1@dont-email.me> <GDvxI.19645$R591.15186@fx37.ams4>
<v3wxI.85192$_jR.41980@fx14.ams4> <sa6v0v$4r0$1@solani.org>
From: bc...@freeuk.com (Bart)
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
MIME-Version: 1.0
In-Reply-To: <sa6v0v$4r0$1@solani.org>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-GB
Content-Transfer-Encoding: 7bit
X-Antivirus: AVG (VPS 210614-0, 14/06/2021), Outbound message
X-Antivirus-Status: Clean
Lines: 75
Message-ID: <aAGxI.151628$co68.48603@fx03.ams4>
X-Complaints-To: http://netreport.virginmedia.com
NNTP-Posting-Date: Mon, 14 Jun 2021 10:55:02 UTC
Organization: virginmedia.com
Date: Mon, 14 Jun 2021 11:54:59 +0100
X-Received-Bytes: 3413
 by: Bart - Mon, 14 Jun 2021 10:54 UTC

On 14/06/2021 08:03, Philipp Klaus Krause wrote:
> Am 14.06.21 um 00:57 schrieb Bart:
>>
>> This should fine if running under Windows. For portable code, you really
>> need to use an ugly set of macros from stdint.h or inttypes.h, since the
>> correct formats vary betweeen Windows and Linux (eg. Linux might need
>> one 'l' rather than two, but I believe 'll' will work too).
>
> The C23 standard from 2023 has the %w modifier:
>
> printf("UINT64_MAX : %w64u\n", UINT64_MAX);
>
> Philipp
>

%w64u is not supported by msvcrt.dll yet.

However why are they still messing about with format codes? One change I
tried with my C compiler was to use a "%?" specifier which adapts itself
to whatever is being printed:

printf("UINT64_MAX/A : %llu\n", UINT64_MAX);
printf("UINT64_MAX/B : %w64u\n", UINT64_MAX);
printf("UINT64_MAX/C : %?\n", UINT64_MAX);

Output is:

UINT64_MAX/A : 18446744073709551615
UINT64_MAX/B : 64u
UINT64_MAX/C : 18446744073709551615

Of course, this is done inside the compiler and is only possible when a
format is a string literal; it does not change the library.

I can use this one format in the OP's program:

printf("INT_MAX : %?\n", INT_MAX);
printf("INT_MIN : %?\n", INT_MIN);
printf("LONG_MAX : %?\n", (long)LONG_MAX);
printf("LONG_MIN : %?\n", (long)LONG_MIN);
printf("UINT_MAX : %?\n", (unsigned int)UINT_MAX);
printf("ULONG_MAX : %?\n", (unsigned long)ULONG_MAX);
printf("USHRT_MAX : %?\n", (unsigned short)USHRT_MAX);
printf("\nFrom stdint.h: \n");
printf("INT8_MAX : %?\n", INT8_MAX);
printf("INT16_MAX : %?\n", INT16_MAX);
printf("INT32_MAX : %?\n", INT32_MAX);
printf("INT64_MAX : %?\n", INT64_MAX);
printf("UINT8_MAX : %?\n", UINT8_MAX); // Fixed FROM UINT16_MAX
printf("UINT16_MAX : %?\n", UINT16_MAX);
printf("UINT32_MAX : %?\n", UINT32_MAX);
printf("UINT64_MAX : %?\n", UINT64_MAX);

And the output is:

INT_MAX : 2147483647
INT_MIN : -2147483648
LONG_MAX : 2147483647
LONG_MIN : -2147483648
UINT_MAX : 4294967295
ULONG_MAX : 4294967295
USHRT_MAX : 65535

From stdint.h:
INT8_MAX : 127
INT16_MAX : 32767
INT32_MAX : 2147483647
INT64_MAX : 9223372036854775807
UINT8_MAX : 255
UINT16_MAX : 65535
UINT32_MAX : 4294967295
UINT64_MAX : 18446744073709551615

Who, in 2023 and beyond, still wants to muck around with format codes?!

Re: #include <stdint.h>

<86bl7vb24m.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17072&group=comp.lang.c#17072

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: #include <stdint.h>
Date: Thu, 24 Jun 2021 10:31:37 -0700
Organization: A noiseless patient Spider
Lines: 51
Message-ID: <86bl7vb24m.fsf@linuxsc.com>
References: <sa5vrs$7d3$1@dont-email.me> <87wnqxxoe3.fsf@nosuchdomain.example.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="5f9785b3afd09fb507884e20b2dfc5bb";
logging-data="11437"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Z2NAnEVKIf1zb2D1smHuyXagsppHCXY0="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:aUiYSCRCweQffHiEGaJVD8pxgaE=
sha1:g+rM6cgGnPFeIpqQsA/Y6YU8FSE=
 by: Tim Rentsch - Thu, 24 Jun 2021 17:31 UTC

Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

[... on printing various integer types ...]

> Using the macros:
>
> #include <stdio.h>
> // #include <stdint.h>
> #include <inttypes.h>
> #include <limits.h>
>
> int main(void) {
> printf("INT_MAX : %d\n", INT_MAX);
> printf("INT_MIN : %d\n", INT_MIN);
> printf("LONG_MAX : %ld\n", LONG_MAX);
> printf("LONG_MIN : %ld\n", LONG_MIN);
> printf("UINT_MAX : %u\n", UINT_MAX);
> printf("ULONG_MAX : %lu\n", ULONG_MAX);
> printf("USHRT_MAX : %u\n", (unsigned)USHRT_MAX);

The cast in the last line is not needed.

> printf("\nFrom stdint.h: \n");
> printf("INT8_MAX : %" PRId8 "\n", INT8_MAX);
> printf("INT16_MAX : %" PRId16 "\n", INT16_MAX);
> printf("INT32_MAX : %" PRId32 "\n", INT32_MAX);
> printf("INT64_MAX : %" PRId64 "\n", INT64_MAX);
> printf("UINT8_MAX : %" PRIu8 "\n", UINT16_MAX);
> printf("UINT16_MAX : %" PRIu16 "\n", UINT16_MAX);
> printf("UINT32_MAX : %" PRIu32 "\n", UINT32_MAX);
> printf("UINT64_MAX : %" PRIu64 "\n", UINT64_MAX);
> }
>
> Most of the casts in your original program are unnecessary, since
> the expressions are already of the type you were casting them to.
> But unsigned short could promote either to signed int or to
> unsigned int, depending on their ranges, so converting to unsigned
> and using "%u" is appropriate. In general, when passed to a
> variadic function like printf, an argument of an integer type
> narrower than int is promoted to int if type's range fits in int,
> to unsigned int otherwise.

The description of how type promotion works is right, however a
cast is still not needed there. The reason is that values given
as variadic arguments are allowed to be the corresponding signed
or unsigned version of the type used to get the value, and that
will work as long as the value is in the set of values common to
both types. If an unsigned short promotes to int, then its value
is guaranteed to be in the set of values representable by both
int and unsigned int, and hence using %u for an uncasted unsigned
short is always safe.

Re: #include <stdint.h>

<874kdnw20s.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17074&group=comp.lang.c#17074

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: #include <stdint.h>
Date: Thu, 24 Jun 2021 11:28:19 -0700
Organization: None to speak of
Lines: 70
Message-ID: <874kdnw20s.fsf@nosuchdomain.example.com>
References: <sa5vrs$7d3$1@dont-email.me>
<87wnqxxoe3.fsf@nosuchdomain.example.com> <86bl7vb24m.fsf@linuxsc.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="70e67a5c90413ba34e7665d352b91ebe";
logging-data="15350"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX180Uf29vgk2IEICwZ8T+ffb"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:KSFMmwmiPGIgooj/bryl+RvsO0A=
sha1:z+aPaAm8joI/sMOvPUc+WxC7Rrc=
 by: Keith Thompson - Thu, 24 Jun 2021 18:28 UTC

Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>
> [... on printing various integer types ...]
>
>> Using the macros:
>>
>> #include <stdio.h>
>> // #include <stdint.h>
>> #include <inttypes.h>
>> #include <limits.h>
>>
>> int main(void) {
>> printf("INT_MAX : %d\n", INT_MAX);
>> printf("INT_MIN : %d\n", INT_MIN);
>> printf("LONG_MAX : %ld\n", LONG_MAX);
>> printf("LONG_MIN : %ld\n", LONG_MIN);
>> printf("UINT_MAX : %u\n", UINT_MAX);
>> printf("ULONG_MAX : %lu\n", ULONG_MAX);
>> printf("USHRT_MAX : %u\n", (unsigned)USHRT_MAX);
>
> The cast in the last line is not needed.
>
>> printf("\nFrom stdint.h: \n");
>> printf("INT8_MAX : %" PRId8 "\n", INT8_MAX);
>> printf("INT16_MAX : %" PRId16 "\n", INT16_MAX);
>> printf("INT32_MAX : %" PRId32 "\n", INT32_MAX);
>> printf("INT64_MAX : %" PRId64 "\n", INT64_MAX);
>> printf("UINT8_MAX : %" PRIu8 "\n", UINT16_MAX);
>> printf("UINT16_MAX : %" PRIu16 "\n", UINT16_MAX);
>> printf("UINT32_MAX : %" PRIu32 "\n", UINT32_MAX);
>> printf("UINT64_MAX : %" PRIu64 "\n", UINT64_MAX);
>> }
>>
>> Most of the casts in your original program are unnecessary, since
>> the expressions are already of the type you were casting them to.
>> But unsigned short could promote either to signed int or to
>> unsigned int, depending on their ranges, so converting to unsigned
>> and using "%u" is appropriate. In general, when passed to a
>> variadic function like printf, an argument of an integer type
>> narrower than int is promoted to int if type's range fits in int,
>> to unsigned int otherwise.
>
> The description of how type promotion works is right, however a
> cast is still not needed there. The reason is that values given
> as variadic arguments are allowed to be the corresponding signed
> or unsigned version of the type used to get the value, and that
> will work as long as the value is in the set of values common to
> both types. If an unsigned short promotes to int, then its value
> is guaranteed to be in the set of values representable by both
> int and unsigned int, and hence using %u for an uncasted unsigned
> short is always safe.

My reading of the standard is that that's certainly the intent, but
it's not quite stated explicitly.

N1570 6.5.2.2 makes a similar guarantee for calls to a function defined
without a prototype.

7.16.1.1 makes the same guarantee for arguments to the va_arg macro,
which makes it clear that printf("%u\n", 1) is *supposed* to work, but I
don't see a guarantee that the call itself (which happens before va_arg
is invoked -- assuming printf even uses va_arg) has defined behavior.

Or I'm missing something.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */

Re: #include <stdint.h>

<878s2zndzc.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17076&group=comp.lang.c#17076

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: #include <stdint.h>
Date: Thu, 24 Jun 2021 22:34:47 +0100
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <878s2zndzc.fsf@bsb.me.uk>
References: <sa5vrs$7d3$1@dont-email.me>
<87wnqxxoe3.fsf@nosuchdomain.example.com> <86bl7vb24m.fsf@linuxsc.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="983aed1809c012a14a794b8d3d8312b0";
logging-data="32358"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+dnBo6M/xb4Ei9wy9BBPMDw2IpOi6xmAs="
Cancel-Lock: sha1:76TMwS6k63lY+2ct59+c8bWAfsg=
sha1:mAsQ7MVlFx81ntS3Gw2VO4Iah98=
X-BSB-Auth: 1.379c10110f509a43d683.20210624223447BST.878s2zndzc.fsf@bsb.me.uk
 by: Ben Bacarisse - Thu, 24 Jun 2021 21:34 UTC

Tim Rentsch <tr.17687@z991.linuxsc.com> writes:

> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>
> [... on printing various integer types ...]
<cut>
>> printf("USHRT_MAX : %u\n", (unsigned)USHRT_MAX);
>
> The cast in the last line is not needed.
<cut>
> The description of how type promotion works is right, however a
> cast is still not needed there. The reason is that values given
> as variadic arguments are allowed to be the corresponding signed
> or unsigned version of the type used to get the value, and that
> will work as long as the value is in the set of values common to
> both types. If an unsigned short promotes to int, then its value
> is guaranteed to be in the set of values representable by both
> int and unsigned int, and hence using %u for an uncasted unsigned
> short is always safe.

It's safe (in practical terms) but 7.21.6.1 paragraph 8 says of the 'u'
conversion specifier:

"o,u,x,X The unsigned int argument is..."

and, later, paragraph 9 says

"... If any argument is not the correct type for the corresponding
conversion specification, the behavior is undefined."

So I am left wondering how one can know that int (the promoted type when
no cast is used) is "the correct type" for the 'u' conversion
specification.

--
Ben.

Re: #include <stdint.h>

<122cd8b8-5ef9-4b3d-a739-a071153cbf5cn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17077&group=comp.lang.c#17077

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a0c:bf4b:: with SMTP id b11mr7950775qvj.11.1624572100095;
Thu, 24 Jun 2021 15:01:40 -0700 (PDT)
X-Received: by 2002:a0c:e84b:: with SMTP id l11mr7767601qvo.36.1624572099921;
Thu, 24 Jun 2021 15:01:39 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!feeder1.feed.usenet.farm!feed.usenet.farm!news-out.netnews.com!news.alt.net!fdc3.netnews.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Thu, 24 Jun 2021 15:01:39 -0700 (PDT)
In-Reply-To: <878s2zndzc.fsf@bsb.me.uk>
Injection-Info: google-groups.googlegroups.com; posting-host=94.246.251.45; posting-account=pysjKgkAAACLegAdYDFznkqjgx_7vlUK
NNTP-Posting-Host: 94.246.251.45
References: <sa5vrs$7d3$1@dont-email.me> <87wnqxxoe3.fsf@nosuchdomain.example.com>
<86bl7vb24m.fsf@linuxsc.com> <878s2zndzc.fsf@bsb.me.uk>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <122cd8b8-5ef9-4b3d-a739-a071153cbf5cn@googlegroups.com>
Subject: Re: #include <stdint.h>
From: oot...@hot.ee (Öö Tiib)
Injection-Date: Thu, 24 Jun 2021 22:01:40 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2707
 by: Öö Tiib - Thu, 24 Jun 2021 22:01 UTC

On Friday, 25 June 2021 at 00:34:58 UTC+3, Ben Bacarisse wrote:
> Tim Rentsch <tr.1...@z991.linuxsc.com> writes:
>
> > Keith Thompson <Keith.S.T...@gmail.com> writes:
> >
> > [... on printing various integer types ...]
> <cut>
> >> printf("USHRT_MAX : %u\n", (unsigned)USHRT_MAX);
> >
> > The cast in the last line is not needed.
> <cut>
> > The description of how type promotion works is right, however a
> > cast is still not needed there. The reason is that values given
> > as variadic arguments are allowed to be the corresponding signed
> > or unsigned version of the type used to get the value, and that
> > will work as long as the value is in the set of values common to
> > both types. If an unsigned short promotes to int, then its value
> > is guaranteed to be in the set of values representable by both
> > int and unsigned int, and hence using %u for an uncasted unsigned
> > short is always safe.
> It's safe (in practical terms) but 7.21.6.1 paragraph 8 says of the 'u'
> conversion specifier:
>
> "o,u,x,X The unsigned int argument is..."
>
> and, later, paragraph 9 says
>
> "... If any argument is not the correct type for the corresponding
> conversion specification, the behavior is undefined."
>
> So I am left wondering how one can know that int (the promoted type when
> no cast is used) is "the correct type" for the 'u' conversion
> specification.

Yes it is strange. IIRC the constant USHRT_MAX may be of type
signed int or unsigned int but can not be of type unsigned short.

Re: #include <stdint.h>

<87r1gqvqzl.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17078&group=comp.lang.c#17078

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: #include <stdint.h>
Date: Thu, 24 Jun 2021 15:26:38 -0700
Organization: None to speak of
Lines: 46
Message-ID: <87r1gqvqzl.fsf@nosuchdomain.example.com>
References: <sa5vrs$7d3$1@dont-email.me>
<87wnqxxoe3.fsf@nosuchdomain.example.com> <86bl7vb24m.fsf@linuxsc.com>
<878s2zndzc.fsf@bsb.me.uk>
<122cd8b8-5ef9-4b3d-a739-a071153cbf5cn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="e76a60976a03f7b22ccc859f0f74fb19";
logging-data="4370"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19MIuVHlSx1dFISH0X8KUUV"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:bThzzU0/gXQt0R1N92uxAIZZZi8=
sha1:9ngAw6doulaqkjb8FPX7gXXYdzg=
 by: Keith Thompson - Thu, 24 Jun 2021 22:26 UTC

Öö Tiib <ootiib@hot.ee> writes:
> On Friday, 25 June 2021 at 00:34:58 UTC+3, Ben Bacarisse wrote:
>> Tim Rentsch <tr.1...@z991.linuxsc.com> writes:
>> > Keith Thompson <Keith.S.T...@gmail.com> writes:
>> >
>> > [... on printing various integer types ...]
>> <cut>
>> >> printf("USHRT_MAX : %u\n", (unsigned)USHRT_MAX);
>> >
>> > The cast in the last line is not needed.
>> <cut>
>> > The description of how type promotion works is right, however a
>> > cast is still not needed there. The reason is that values given
>> > as variadic arguments are allowed to be the corresponding signed
>> > or unsigned version of the type used to get the value, and that
>> > will work as long as the value is in the set of values common to
>> > both types. If an unsigned short promotes to int, then its value
>> > is guaranteed to be in the set of values representable by both
>> > int and unsigned int, and hence using %u for an uncasted unsigned
>> > short is always safe.
>> It's safe (in practical terms) but 7.21.6.1 paragraph 8 says of the 'u'
>> conversion specifier:
>>
>> "o,u,x,X The unsigned int argument is..."
>>
>> and, later, paragraph 9 says
>>
>> "... If any argument is not the correct type for the corresponding
>> conversion specification, the behavior is undefined."
>>
>> So I am left wondering how one can know that int (the promoted type when
>> no cast is used) is "the correct type" for the 'u' conversion
>> specification.
>
> Yes it is strange. IIRC the constant USHRT_MAX may be of type
> signed int or unsigned int but can not be of type unsigned short.

Correct. Which means that if you want to print the value of USHRT_MAX
safely, you can do:

printf("USHRT_MAX = %u\n", (unsigned)USHRT_MAX);

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */

Re: #include <stdint.h>

<86wnpx6wl1.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17458&group=comp.lang.c#17458

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: #include <stdint.h>
Date: Sun, 11 Jul 2021 02:14:50 -0700
Organization: A noiseless patient Spider
Lines: 91
Message-ID: <86wnpx6wl1.fsf@linuxsc.com>
References: <sa5vrs$7d3$1@dont-email.me> <87wnqxxoe3.fsf@nosuchdomain.example.com> <86bl7vb24m.fsf@linuxsc.com> <878s2zndzc.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="52e1adecb53146628fb5ee5c083fc413";
logging-data="21882"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+CiYulhnU+eymu0zohihqZBHSG3Dt7orw="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:bv2OorN3XDR17BOeczuXrMoRpmU=
sha1:8Rce5lZIAQDG7H7AUTVd9cOWEkE=
 by: Tim Rentsch - Sun, 11 Jul 2021 09:14 UTC

Ben Bacarisse <ben.usenet@bsb.me.uk> writes:

> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>
>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>
>> [... on printing various integer types ...]
>
> <cut>
>
>>> printf("USHRT_MAX : %u\n", (unsigned)USHRT_MAX);
>>
>> The cast in the last line is not needed.
>
> <cut>
>
>> The description of how type promotion works is right, however a
>> cast is still not needed there. The reason is that values given
>> as variadic arguments are allowed to be the corresponding signed
>> or unsigned version of the type used to get the value, and that
>> will work as long as the value is in the set of values common to
>> both types. If an unsigned short promotes to int, then its value
>> is guaranteed to be in the set of values representable by both
>> int and unsigned int, and hence using %u for an uncasted unsigned
>> short is always safe.
>
> It's safe (in practical terms) but 7.21.6.1 paragraph 8 says of the
> 'u' conversion specifier:
>
> "o,u,x,X The unsigned int argument is..."
>
> and, later, paragraph 9 says
>
> "... If any argument is not the correct type for the corresponding
> conversion specification, the behavior is undefined."
>
> So I am left wondering how one can know that int (the promoted type
> when no cast is used) is "the correct type" for the 'u' conversion
> specification.

I believe the rule about variadic arguments applying to printf
arguments is both what was intended and how the C standard is
generally read by others, including in particular implementors.
Consider two possibilities:

One: the rules for type correctness for printf arguments are
defined only by the somewhat vague phrase "the correct type" and
are different from the rules for other functions taking variadic
arguments; or

Two: the rules for type correctness for printf arguments are the
same as the rules for type correctness for other functions taking
variadic arguments (taking into account of course that different
specifiers imply different nominal argument types).

For completeness I should mention the reference Keith Thompson
pointed out, 7.16.1.1 (paragraph 2), that gives this rule for
the 'va_arg' macro, ie, that the corresponding unsigned type
is okay for a signed type specification, and vice versa, provided
the argument value given is representable in both types.

Are the rules for type correctness for printf idiosyncratic and
specific to printf, or are they the same as other variadic
functions? To me the second case seems much more likely.

Note that both gcc and clang, running with a -Wformat option
given, accept with no diagnostic a signed argument for an
unsigned specifier, and vice versa.

At this point I realized that I haven't really responded to your
implied question about "how one can know that", for example, an
int can be given for a %u conversion sequence. At least right
now I think the best answer I can give you is to think like an
implementor. The people who write the C standard aren't lawyers,
they are regular software developers, with a fair amount of
implementation experience. They aren't thinking mainly about the
words. They are, I belive, thinking first in terms of how things
are implemented, and only later about how to express that in
normal written language. If we think about it in terms of
implementation the relationship seems pretty straightforward.
The allowance for unsigned/signed interchangeability is given
explicitly in the description for va_arg; usually the C standard
avoids giving the same rule in more than one place, so it isn't
surprising that it wouldn't be repeated in the description of
arguments for *printf functions, but instead just referred to by
the phrase "the correct type". Does that make sense?

Incidentally, in C90 neither the sentence about "the correct type"
nor the extra type rules for va_arg were present. Both were added
in C99. I don't know whether that has any bearing on the question
at hand, but it's an interesting historical coincidence.

Re: #include <stdint.h>

<86sg0l6uza.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17459&group=comp.lang.c#17459

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: #include <stdint.h>
Date: Sun, 11 Jul 2021 02:49:29 -0700
Organization: A noiseless patient Spider
Lines: 85
Message-ID: <86sg0l6uza.fsf@linuxsc.com>
References: <sa5vrs$7d3$1@dont-email.me> <87wnqxxoe3.fsf@nosuchdomain.example.com> <86bl7vb24m.fsf@linuxsc.com> <874kdnw20s.fsf@nosuchdomain.example.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="52e1adecb53146628fb5ee5c083fc413";
logging-data="2656"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19J13rE8nEurskWkLk9K2Whwt/ORAZO/Wc="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:kpc+2mW3sqdibUtMm5+p0ZAHfgc=
sha1:Ehmuxxcw8dsexlR0zjVQExBkdJo=
 by: Tim Rentsch - Sun, 11 Jul 2021 09:49 UTC

Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>
>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>
>> [... on printing various integer types ...]
>>
>>> Using the macros:
>>>
>>> #include <stdio.h>
>>> // #include <stdint.h>
>>> #include <inttypes.h>
>>> #include <limits.h>
>>>
>>> int main(void) {
>>> printf("INT_MAX : %d\n", INT_MAX);
>>> printf("INT_MIN : %d\n", INT_MIN);
>>> printf("LONG_MAX : %ld\n", LONG_MAX);
>>> printf("LONG_MIN : %ld\n", LONG_MIN);
>>> printf("UINT_MAX : %u\n", UINT_MAX);
>>> printf("ULONG_MAX : %lu\n", ULONG_MAX);
>>> printf("USHRT_MAX : %u\n", (unsigned)USHRT_MAX);
>>
>> The cast in the last line is not needed.
>>
>>> printf("\nFrom stdint.h: \n");
>>> printf("INT8_MAX : %" PRId8 "\n", INT8_MAX);
>>> printf("INT16_MAX : %" PRId16 "\n", INT16_MAX);
>>> printf("INT32_MAX : %" PRId32 "\n", INT32_MAX);
>>> printf("INT64_MAX : %" PRId64 "\n", INT64_MAX);
>>> printf("UINT8_MAX : %" PRIu8 "\n", UINT16_MAX);
>>> printf("UINT16_MAX : %" PRIu16 "\n", UINT16_MAX);
>>> printf("UINT32_MAX : %" PRIu32 "\n", UINT32_MAX);
>>> printf("UINT64_MAX : %" PRIu64 "\n", UINT64_MAX);
>>> }
>>>
>>> Most of the casts in your original program are unnecessary, since
>>> the expressions are already of the type you were casting them to.
>>> But unsigned short could promote either to signed int or to
>>> unsigned int, depending on their ranges, so converting to unsigned
>>> and using "%u" is appropriate. In general, when passed to a
>>> variadic function like printf, an argument of an integer type
>>> narrower than int is promoted to int if type's range fits in int,
>>> to unsigned int otherwise.
>>
>> The description of how type promotion works is right, however a
>> cast is still not needed there. The reason is that values given
>> as variadic arguments are allowed to be the corresponding signed
>> or unsigned version of the type used to get the value, and that
>> will work as long as the value is in the set of values common to
>> both types. If an unsigned short promotes to int, then its value
>> is guaranteed to be in the set of values representable by both
>> int and unsigned int, and hence using %u for an uncasted unsigned
>> short is always safe.
>
> My reading of the standard is that that's certainly the intent, but
> it's not quite stated explicitly.
>
> N1570 6.5.2.2 makes a similar guarantee for calls to a function defined
> without a prototype.
>
> 7.16.1.1 makes the same guarantee for arguments to the va_arg macro,
> which makes it clear that printf("%u\n", 1) is *supposed* to work, but I
> don't see a guarantee that the call itself (which happens before va_arg
> is invoked -- assuming printf even uses va_arg) has defined behavior.
>
> Or I'm missing something.

I wrote a long reply to Ben Bacarisse in this same thread, you
may want to read that reply in addition to what I write here.

Basically the question boils down to what is meant by the
somewhat vague phrase "the correct type". I believe that phrase
is meant to refer to the rules of 7.16.1.1. If you want to say
there's an ambiguity about what is meant, certainly I could agree
with that. For purposes of posting in comp.lang.c, my usual rule
is to judge the language according to what meaning is intended,
and since here we are in agreement about what is intended here we
are not in conflict. Whether the C standard "actually says" that
the va_arg rules apply to *printf functions is, I think, not
an answerable question, and in any case not really a useful
question for purposes of comp.lang.c. I am glad we agree about
what rule is intended, and IMO that is really all that matters
for the present discussion.

Re: #include <stdint.h>

<87mtqs5vre.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17466&group=comp.lang.c#17466

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: #include <stdint.h>
Date: Sun, 11 Jul 2021 15:30:13 -0700
Organization: None to speak of
Lines: 99
Message-ID: <87mtqs5vre.fsf@nosuchdomain.example.com>
References: <sa5vrs$7d3$1@dont-email.me>
<87wnqxxoe3.fsf@nosuchdomain.example.com> <86bl7vb24m.fsf@linuxsc.com>
<874kdnw20s.fsf@nosuchdomain.example.com> <86sg0l6uza.fsf@linuxsc.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="d99a2aa5e30c72b9011dead7e6361f9f";
logging-data="13339"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/RTK78JeMZ1A8k5chXVvTx"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:691SxFHd3bF3bE7Z22IzfY4EMVU=
sha1:pvOB+Du9CcFAWwcYYI8fbY1D4TE=
 by: Keith Thompson - Sun, 11 Jul 2021 22:30 UTC

Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>> [... on printing various integer types ...]
>>>
>>>> Using the macros:
>>>>
>>>> #include <stdio.h>
>>>> // #include <stdint.h>
>>>> #include <inttypes.h>
>>>> #include <limits.h>
>>>>
>>>> int main(void) {
>>>> printf("INT_MAX : %d\n", INT_MAX);
>>>> printf("INT_MIN : %d\n", INT_MIN);
>>>> printf("LONG_MAX : %ld\n", LONG_MAX);
>>>> printf("LONG_MIN : %ld\n", LONG_MIN);
>>>> printf("UINT_MAX : %u\n", UINT_MAX);
>>>> printf("ULONG_MAX : %lu\n", ULONG_MAX);
>>>> printf("USHRT_MAX : %u\n", (unsigned)USHRT_MAX);
>>>
>>> The cast in the last line is not needed.
>>>
>>>> printf("\nFrom stdint.h: \n");
>>>> printf("INT8_MAX : %" PRId8 "\n", INT8_MAX);
>>>> printf("INT16_MAX : %" PRId16 "\n", INT16_MAX);
>>>> printf("INT32_MAX : %" PRId32 "\n", INT32_MAX);
>>>> printf("INT64_MAX : %" PRId64 "\n", INT64_MAX);
>>>> printf("UINT8_MAX : %" PRIu8 "\n", UINT16_MAX);
>>>> printf("UINT16_MAX : %" PRIu16 "\n", UINT16_MAX);
>>>> printf("UINT32_MAX : %" PRIu32 "\n", UINT32_MAX);
>>>> printf("UINT64_MAX : %" PRIu64 "\n", UINT64_MAX);
>>>> }
>>>>
>>>> Most of the casts in your original program are unnecessary, since
>>>> the expressions are already of the type you were casting them to.
>>>> But unsigned short could promote either to signed int or to
>>>> unsigned int, depending on their ranges, so converting to unsigned
>>>> and using "%u" is appropriate. In general, when passed to a
>>>> variadic function like printf, an argument of an integer type
>>>> narrower than int is promoted to int if type's range fits in int,
>>>> to unsigned int otherwise.
>>>
>>> The description of how type promotion works is right, however a
>>> cast is still not needed there. The reason is that values given
>>> as variadic arguments are allowed to be the corresponding signed
>>> or unsigned version of the type used to get the value, and that
>>> will work as long as the value is in the set of values common to
>>> both types. If an unsigned short promotes to int, then its value
>>> is guaranteed to be in the set of values representable by both
>>> int and unsigned int, and hence using %u for an uncasted unsigned
>>> short is always safe.
>>
>> My reading of the standard is that that's certainly the intent, but
>> it's not quite stated explicitly.
>>
>> N1570 6.5.2.2 makes a similar guarantee for calls to a function defined
>> without a prototype.
>>
>> 7.16.1.1 makes the same guarantee for arguments to the va_arg macro,
>> which makes it clear that printf("%u\n", 1) is *supposed* to work, but I
>> don't see a guarantee that the call itself (which happens before va_arg
>> is invoked -- assuming printf even uses va_arg) has defined behavior.
>>
>> Or I'm missing something.
>
> I wrote a long reply to Ben Bacarisse in this same thread, you
> may want to read that reply in addition to what I write here.
>
> Basically the question boils down to what is meant by the
> somewhat vague phrase "the correct type". I believe that phrase
> is meant to refer to the rules of 7.16.1.1. If you want to say
> there's an ambiguity about what is meant, certainly I could agree
> with that. For purposes of posting in comp.lang.c, my usual rule
> is to judge the language according to what meaning is intended,
> and since here we are in agreement about what is intended here we
> are not in conflict. Whether the C standard "actually says" that
> the va_arg rules apply to *printf functions is, I think, not
> an answerable question, and in any case not really a useful
> question for purposes of comp.lang.c. I am glad we agree about
> what rule is intended, and IMO that is really all that matters
> for the present discussion.

I mostly agree, but I disagree with your statement about the va_arg
rules applying to *printf.

The standard doesn't say that the *printf functions use va_arg. The
question of whether the standard *actually says* that va_arg rules apply
to *printf functions is, I think, answerable, and the answer is no.

Whether that matters is another question, but surely a question about
whether the standard says something can be resolved by reading the
standard.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: #include <stdint.h>

<86h7gu7dki.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17513&group=comp.lang.c#17513

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: #include <stdint.h>
Date: Fri, 16 Jul 2021 03:33:49 -0700
Organization: A noiseless patient Spider
Lines: 114
Message-ID: <86h7gu7dki.fsf@linuxsc.com>
References: <sa5vrs$7d3$1@dont-email.me> <87wnqxxoe3.fsf@nosuchdomain.example.com> <86bl7vb24m.fsf@linuxsc.com> <874kdnw20s.fsf@nosuchdomain.example.com> <86sg0l6uza.fsf@linuxsc.com> <87mtqs5vre.fsf@nosuchdomain.example.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="09634a13793bf13421bcf3f217467df0";
logging-data="9110"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ftxb08GmOk08DZT0gdqYp1vMXUUT23wM="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:vMkCkyX6BhHI6cpfSEKROeBVN78=
sha1:ocCDd/8y9sjHoZBIvo9gTPgFH9I=
 by: Tim Rentsch - Fri, 16 Jul 2021 10:33 UTC

Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>
>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>
>>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>>
>>>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>>> [... on printing various integer types ...]
>>>>
>>>>> Using the macros:
>>>>>
>>>>> #include <stdio.h>
>>>>> // #include <stdint.h>
>>>>> #include <inttypes.h>
>>>>> #include <limits.h>
>>>>>
>>>>> int main(void) {
>>>>> printf("INT_MAX : %d\n", INT_MAX);
>>>>> printf("INT_MIN : %d\n", INT_MIN);
>>>>> printf("LONG_MAX : %ld\n", LONG_MAX);
>>>>> printf("LONG_MIN : %ld\n", LONG_MIN);
>>>>> printf("UINT_MAX : %u\n", UINT_MAX);
>>>>> printf("ULONG_MAX : %lu\n", ULONG_MAX);
>>>>> printf("USHRT_MAX : %u\n", (unsigned)USHRT_MAX);
>>>>
>>>> The cast in the last line is not needed.
>>>>
>>>>> printf("\nFrom stdint.h: \n");
>>>>> printf("INT8_MAX : %" PRId8 "\n", INT8_MAX);
>>>>> printf("INT16_MAX : %" PRId16 "\n", INT16_MAX);
>>>>> printf("INT32_MAX : %" PRId32 "\n", INT32_MAX);
>>>>> printf("INT64_MAX : %" PRId64 "\n", INT64_MAX);
>>>>> printf("UINT8_MAX : %" PRIu8 "\n", UINT16_MAX);
>>>>> printf("UINT16_MAX : %" PRIu16 "\n", UINT16_MAX);
>>>>> printf("UINT32_MAX : %" PRIu32 "\n", UINT32_MAX);
>>>>> printf("UINT64_MAX : %" PRIu64 "\n", UINT64_MAX);
>>>>> }
>>>>>
>>>>> Most of the casts in your original program are unnecessary, since
>>>>> the expressions are already of the type you were casting them to.
>>>>> But unsigned short could promote either to signed int or to
>>>>> unsigned int, depending on their ranges, so converting to unsigned
>>>>> and using "%u" is appropriate. In general, when passed to a
>>>>> variadic function like printf, an argument of an integer type
>>>>> narrower than int is promoted to int if type's range fits in int,
>>>>> to unsigned int otherwise.
>>>>
>>>> The description of how type promotion works is right, however a
>>>> cast is still not needed there. The reason is that values given
>>>> as variadic arguments are allowed to be the corresponding signed
>>>> or unsigned version of the type used to get the value, and that
>>>> will work as long as the value is in the set of values common to
>>>> both types. If an unsigned short promotes to int, then its value
>>>> is guaranteed to be in the set of values representable by both
>>>> int and unsigned int, and hence using %u for an uncasted unsigned
>>>> short is always safe.
>>>
>>> My reading of the standard is that that's certainly the intent, but
>>> it's not quite stated explicitly.
>>>
>>> N1570 6.5.2.2 makes a similar guarantee for calls to a function defined
>>> without a prototype.
>>>
>>> 7.16.1.1 makes the same guarantee for arguments to the va_arg macro,
>>> which makes it clear that printf("%u\n", 1) is *supposed* to work, but I
>>> don't see a guarantee that the call itself (which happens before va_arg
>>> is invoked -- assuming printf even uses va_arg) has defined behavior.
>>>
>>> Or I'm missing something.
>>
>> I wrote a long reply to Ben Bacarisse in this same thread, you
>> may want to read that reply in addition to what I write here.
>>
>> Basically the question boils down to what is meant by the
>> somewhat vague phrase "the correct type". I believe that phrase
>> is meant to refer to the rules of 7.16.1.1. If you want to say
>> there's an ambiguity about what is meant, certainly I could agree
>> with that. For purposes of posting in comp.lang.c, my usual rule
>> is to judge the language according to what meaning is intended,
>> and since here we are in agreement about what is intended here we
>> are not in conflict. Whether the C standard "actually says" that
>> the va_arg rules apply to *printf functions is, I think, not
>> an answerable question, and in any case not really a useful
>> question for purposes of comp.lang.c. I am glad we agree about
>> what rule is intended, and IMO that is really all that matters
>> for the present discussion.
>
> I mostly agree, but I disagree with your statement about the va_arg
> rules applying to *printf.
>
> The standard doesn't say that the *printf functions use va_arg. The
> question of whether the standard *actually says* that va_arg rules
> apply to *printf functions is, I think, answerable, and the answer
> is no.
>
> Whether that matters is another question, but surely a question
> about whether the standard says something can be resolved by reading
> the standard.

I think you misunderstood what I was saying. There is no
question about what words are present. What the words mean is
another story. In many cases if not most cases the meaning
of sentences written in English is at least partly subjective.
That is the case here. To talk about what the words "actually
say" is to talk about meaning, and here the meaning is
ambiguous. The phrase "the correct type" is not well-defined.
In fact, since it has not been given an explicit definition,
someone might conclude that a *printf format that needs any
arguments at all will necessarily lead to undefined behavior.
I think you want to ascribe some sort of objective meaning
to the text, but the use of the undefined phrase "the correct
type" makes that impossible.

Re: #include <stdint.h>

<87a6mm2gzj.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17524&group=comp.lang.c#17524

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: #include <stdint.h>
Date: Fri, 16 Jul 2021 12:31:12 -0700
Organization: None to speak of
Lines: 80
Message-ID: <87a6mm2gzj.fsf@nosuchdomain.example.com>
References: <sa5vrs$7d3$1@dont-email.me>
<87wnqxxoe3.fsf@nosuchdomain.example.com> <86bl7vb24m.fsf@linuxsc.com>
<874kdnw20s.fsf@nosuchdomain.example.com> <86sg0l6uza.fsf@linuxsc.com>
<87mtqs5vre.fsf@nosuchdomain.example.com> <86h7gu7dki.fsf@linuxsc.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="25c9c1bea30ea2af62c752c5e5bf9013";
logging-data="16912"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/hFPZ/8WTJXhPhi6fSX0E+"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:5LsH8UDEF+pMrlQG/DehAC695Bg=
sha1:dXTst0PgEWRa4rzyDzCgRrRkjQU=
 by: Keith Thompson - Fri, 16 Jul 2021 19:31 UTC

Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
[...]
>>> Basically the question boils down to what is meant by the
>>> somewhat vague phrase "the correct type". I believe that phrase
>>> is meant to refer to the rules of 7.16.1.1. If you want to say
>>> there's an ambiguity about what is meant, certainly I could agree
>>> with that. For purposes of posting in comp.lang.c, my usual rule
>>> is to judge the language according to what meaning is intended,
>>> and since here we are in agreement about what is intended here we
>>> are not in conflict. Whether the C standard "actually says" that
>>> the va_arg rules apply to *printf functions is, I think, not
>>> an answerable question, and in any case not really a useful
>>> question for purposes of comp.lang.c. I am glad we agree about
>>> what rule is intended, and IMO that is really all that matters
>>> for the present discussion.
>>
>> I mostly agree, but I disagree with your statement about the va_arg
>> rules applying to *printf.
>>
>> The standard doesn't say that the *printf functions use va_arg. The
>> question of whether the standard *actually says* that va_arg rules
>> apply to *printf functions is, I think, answerable, and the answer
>> is no.
>>
>> Whether that matters is another question, but surely a question
>> about whether the standard says something can be resolved by reading
>> the standard.
>
> I think you misunderstood what I was saying. There is no
> question about what words are present. What the words mean is
> another story. In many cases if not most cases the meaning
> of sentences written in English is at least partly subjective.
> That is the case here. To talk about what the words "actually
> say" is to talk about meaning, and here the meaning is
> ambiguous. The phrase "the correct type" is not well-defined.
> In fact, since it has not been given an explicit definition,
> someone might conclude that a *printf format that needs any
> arguments at all will necessarily lead to undefined behavior.
> I think you want to ascribe some sort of objective meaning
> to the text, but the use of the undefined phrase "the correct
> type" makes that impossible.

I think it's not so much misunderstanding as disagreement.

You wrote:

Whether the C standard "actually says" that the va_arg rules apply
to *printf functions is, I think, not an answerable question, and in
any case not really a useful question for purposes of comp.lang.c.

I simply disagree. It is an answerable question, and the answer is no;
the standard does not say that anywhere. It provides <stdarg.h> as *a*
mechanism for implementing variadic functions, and specifies the rules
that apply when va_arg is used, but it simply does not say that printf
is implemented using va_arg or that it follows the rules specified for
va_arg. A footnote says "The macros defined in the <stdarg.h> header
(7.16) may be used to access arguments that correspond to the
ellipsis.", which clearly implies the possibility of other mechanisms.

If it said that, there would be words to that effect. There
aren't. (Of course I'm open to correction if I'm missed something.)

As for "the correct type", I suggest that that phrase is inconsistent
with there being more than one correct type. The phrase "the correct
type" is not rigorously defined, but it is unambiguous that it refers to
one type. int and unsigned int are two distinct types; it is not
possible that they can both qualify as "the correct type". If it had
said "a correct type", that would leave open the possibility that either
int or unsigned int might be correct as an argument corresponding to
"%d", for example.

You see ambiguity in the words used in the standard that, as I read it,
just isn't there.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: #include <stdint.h>

<86h7e2tawh.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18448&group=comp.lang.c#18448

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: #include <stdint.h>
Date: Thu, 30 Sep 2021 07:07:10 -0700
Organization: A noiseless patient Spider
Lines: 58
Message-ID: <86h7e2tawh.fsf@linuxsc.com>
References: <sa5vrs$7d3$1@dont-email.me> <87wnqxxoe3.fsf@nosuchdomain.example.com> <86bl7vb24m.fsf@linuxsc.com> <874kdnw20s.fsf@nosuchdomain.example.com> <86sg0l6uza.fsf@linuxsc.com> <87mtqs5vre.fsf@nosuchdomain.example.com> <86h7gu7dki.fsf@linuxsc.com> <87a6mm2gzj.fsf@nosuchdomain.example.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="d4788905ada0446dfc3ae6b02ecc1355";
logging-data="15857"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18bMPSgmUloob/xre1M5AL74p+Q/wMpM1w="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:9yigk97chO8v06oUOkR9hzIKr3Y=
sha1:r3zpEjP3OuqPF883+cAqXafv4d0=
 by: Tim Rentsch - Thu, 30 Sep 2021 14:07 UTC

Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
> [...]
>>>> Basically the question boils down to what is meant by the
>>>> somewhat vague phrase "the correct type". I believe that phrase
>>>> is meant to refer to the rules of 7.16.1.1. If you want to say
>>>> there's an ambiguity about what is meant, certainly I could agree
>>>> with that. For purposes of posting in comp.lang.c, my usual rule
>>>> is to judge the language according to what meaning is intended,
>>>> and since here we are in agreement about what is intended here we
>>>> are not in conflict. Whether the C standard "actually says" that
>>>> the va_arg rules apply to *printf functions is, I think, not
>>>> an answerable question, and in any case not really a useful
>>>> question for purposes of comp.lang.c. I am glad we agree about
>>>> what rule is intended, and IMO that is really all that matters
>>>> for the present discussion.
>>>
>>> I mostly agree, but I disagree with your statement about the va_arg
>>> rules applying to *printf.
>>>
>>> The standard doesn't say that the *printf functions use va_arg. The
>>> question of whether the standard *actually says* that va_arg rules
>>> apply to *printf functions is, I think, answerable, and the answer
>>> is no.
>>>
>>> Whether that matters is another question, but surely a question
>>> about whether the standard says something can be resolved by reading
>>> the standard.
>>
>> I think you misunderstood what I was saying. There is no
>> question about what words are present. What the words mean is
>> another story. In many cases if not most cases the meaning
>> of sentences written in English is at least partly subjective.
>> That is the case here. To talk about what the words "actually
>> say" is to talk about meaning, and here the meaning is
>> ambiguous. The phrase "the correct type" is not well-defined.
>> In fact, since it has not been given an explicit definition,
>> someone might conclude that a *printf format that needs any
>> arguments at all will necessarily lead to undefined behavior.
>> I think you want to ascribe some sort of objective meaning
>> to the text, but the use of the undefined phrase "the correct
>> type" makes that impossible.
>
> I think it's not so much misunderstanding as disagreement.
>
> You wrote:
>
> Whether the C standard "actually says" that the va_arg rules apply
> to *printf functions is, I think, not an answerable question, and in
> any case not really a useful question for purposes of comp.lang.c.
>
> I simply disagree. It is an answerable question, [...]

The question I am considering does not have an objective answer.
Did you not understand that?

Re: #include <stdint.h>

<87h7e2hxy3.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18451&group=comp.lang.c#18451

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: #include <stdint.h>
Date: Thu, 30 Sep 2021 08:42:28 -0700
Organization: None to speak of
Lines: 23
Message-ID: <87h7e2hxy3.fsf@nosuchdomain.example.com>
References: <sa5vrs$7d3$1@dont-email.me>
<87wnqxxoe3.fsf@nosuchdomain.example.com> <86bl7vb24m.fsf@linuxsc.com>
<874kdnw20s.fsf@nosuchdomain.example.com> <86sg0l6uza.fsf@linuxsc.com>
<87mtqs5vre.fsf@nosuchdomain.example.com> <86h7gu7dki.fsf@linuxsc.com>
<87a6mm2gzj.fsf@nosuchdomain.example.com> <86h7e2tawh.fsf@linuxsc.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="4b075a85c80fa8b78011f466bfabf6da";
logging-data="23273"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+RYxxhESfCZlx1txYmzKFy"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:GA7VVaYpdfDOcmxD+lbwqgyiROU=
sha1:iZhHwsm1LH/Rpb5m8tPSUY95QLA=
 by: Keith Thompson - Thu, 30 Sep 2021 15:42 UTC

Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
[...]
>> I think it's not so much misunderstanding as disagreement.
>>
>> You wrote:
>>
>> Whether the C standard "actually says" that the va_arg rules apply
>> to *printf functions is, I think, not an answerable question, and in
>> any case not really a useful question for purposes of comp.lang.c.
>>
>> I simply disagree. It is an answerable question, [...]
>
> The question I am considering does not have an objective answer.
> Did you not understand that?

I understood what you said. I think you're wrong. Did you not
understand that?

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor