Path: csiph.com!weretis.net!feeder8.news.weretis.net!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: Dymamic arrays: memory management and naming
Date: Mon, 25 Sep 2023 13:21:33 -0700
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <86a5taj96a.fsf@linuxsc.com>
References: <20230909132336.99cdb303ad685bc1e40f92df@gmail.moc> <86ediwmk8b.fsf@linuxsc.com> <20230919011018.d9ed14da6e842291d47b69d7@gmail.moc> <86jzsmkqyu.fsf@linuxsc.com> <20230924003915.51bb21339ab1c551eba59162@gmail.moc> <20230924081911.947@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="b3d2a53e0ccd70cd5158b7b6e81b5d4b"; logging-data="2202477"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/3QBBhh6nJZvBR4eFMHzVBg5iSAEU7jTk="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:Xofo4sSG3E2+ShANYN6fs/O2a7k= sha1:KRgo8Q9NtdQhw7ovvMUkk0HCH6k=
Xref: csiph.com comp.lang.c:176387
Kaz Kylheku <864-117-4973@kylheku.com> writes:
> People reviewing C code should know the utter basics, like that short
> promotes to int. This is not an unreasonable expectation.
Amusing, in light of what follows.
> [...]
>
> h only makes sense if you're passing a signed argument and want it
> printed as unsigned. Say we have 16 bit short and 32 bit int.
> Then "%u"/(short) -1 will print as 429496725, whereas "%hu"/(short) -1
> will obtain the desired 65535.
Both of those have undefined behavior.