| Deutsch English Français Italiano |
|
<87msnlx3bm.fsf@bsb.me.uk> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!weretis.net!feeder9.news.weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Ben Bacarisse <ben@bsb.me.uk>
Newsgroups: comp.lang.c
Subject: Re: "undefined behavior"?
Date: Sat, 15 Jun 2024 23:13:01 +0100
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <87msnlx3bm.fsf@bsb.me.uk>
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>
<v4dtlt$23m6i$1@dont-email.me> <NoEaO.2646$J8n7.2264@fx12.iad>
<v4fc5j$2cksu$1@dont-email.me> <v4ff97$2d8l1$1@dont-email.me>
<87o784xusf.fsf@bsb.me.uk> <v4g7i3$2icc2$1@dont-email.me>
<87ikybycj6.fsf@bsb.me.uk> <v4hk5v$2tttf$1@dont-email.me>
<87cyojxlgj.fsf@bsb.me.uk> <v4igj8$330vf$2@dont-email.me>
<v4ko7d$3jbip$1@dont-email.me> <v4kput$3joiu$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 16 Jun 2024 00:13:00 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="4454bce243354ff30bc38dcd2528bf41";
logging-data="3844200"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX196MOPTw0YtGk6ieRRsxVj8MvOmpj/Ni7E="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:ys09jQmWrJRbB5HjQKyrpVESUe8=
sha1:48Solxb7NuGekHw9IaqxUXQ9yB0=
X-BSB-Auth: 1.47f0773d2b75af17a1b7.20240615231301BST.87msnlx3bm.fsf@bsb.me.uk
Bytes: 2740
Richard Harnden <richard.nospam@gmail.invalid> writes:
> On 15/06/2024 19:57, David Brown wrote:
>> If you want BBX_RGBA to be a typedef for an unsigned 32-bit integer,
>> write:
>> typedef uint32_t BBX_RGBA;
>> If you want bbx_rgba() to be a function that is typesafe, correct, and
>> efficient (for any decent compiler), write :
>> static inline BBX_RGBA bbx_rgba(uint32_t r, uint32_t g,
>> uint32_t b, uint32_t a)
>> {
>> return (r << 24) | (g << 16) | (b << 8) | a;
>> }
>>
>
> Shouldn't that be ... ?
>
> static inline BBX_RGBA bbx_rgba(uint8_t r, uint8_t g,
> uint8_t b, uint8_t a)
Maybe, but the function then needs more care as uint8_t will promote to
int and then r << 24 can be undefined. One needs
((BBX_RGBA)r << 24) | (g << 16) | (b << 8) | a
(assuming that int is never going to be 16 bits or the same issue comes
up with the g << 16 shift). Given this assumption, I'd just check that
unsigned int is at least 32 bits are use that for BBX_RGBA.
--
Ben.