Deutsch   English   Français   Italiano  
<v4dtlt$23m6i$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Malcolm McLean <malcolm.arthur.mclean@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: "undefined behavior"?
Date: Thu, 13 Jun 2024 05:47:57 +0100
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <v4dtlt$23m6i$1@dont-email.me>
References: <666a095a$0$952$882e4bbb@reader.netnews.com>
 <8t3k6j5ikf5mvimvksv2t91gbt11ljdfgb@4ax.com>
 <666a18de$0$958$882e4bbb@reader.netnews.com>
 <87y1796bfn.fsf@nosuchdomain.example.com>
 <666a2a30$0$952$882e4bbb@reader.netnews.com>
 <87tthx65qu.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 13 Jun 2024 06:47:58 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="3f1d35f1df29894379c714fe809cf0a2";
	logging-data="2218194"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19MrUYAA71IWEJ0juX+wubIwhvk+ioAOF8="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:vYelRtCeURHRJOu77FSImYmhfbE=
In-Reply-To: <87tthx65qu.fsf@nosuchdomain.example.com>
Content-Language: en-GB
Bytes: 2328

On 13/06/2024 01:33, Keith Thompson wrote:
>
> printf is a variadic function, so the types of the arguments after
> the format string are not specified in its declaration.  The printf
> function has to *assume* that arguments have the types specified
> by the format string.  This:
>      printf("%d\n", foo);
> (probably) has undefined behavior if foo is of type size_t.
 >
And isn't that a nightmare?
> There is no implicit conversion to the expected type.  Note that
> the format string doesn't have to be a string literal, so it's
> not always even possible for the compiler to check the types.
> Variadic functions give you a lot of flexibility at the cost of
> making some type errors difficult to detect.
> 
> (I wrote "probably" because size_t *might* be a typedef for unsigned
> int, and there are special rules about arguments of corresponding
> signed and unsigned types.)
> 

We just can't have size_t variables swilling around in prgrams for these 
reasons.
-- 
Check out my hobby project.
http://malcolmmclean.github.io/babyxrc