Article View: comp.lang.c
Article #1358Re: Rationales for result type of operations using operators like '+='
From: Lawrence D’Oliveiro
Date: Fri, 06 Nov 2026 22:03
Date: Fri, 06 Nov 2026 22:03
94 lines
3818 bytes
3818 bytes
On Thu, 5 Nov 2026 14:38:58 +0000, Richard Harnden wrote:
> C follows BODMAS (or PEMDAS) doesn't it? Nothing wrong with adding
> extra brackets if it make the intention clearer.
Parenthesis clutter soon reaches the point where it is detracting from
readability, rather than adding to it.
Another option is, the window (or page) showing your code is
two-dimensional; why not take advantage of that in the layout?
The human eye is good at spotting shapes, after all:
if
(
same_pix_as != 0
and
(
result->baseaddr != same_pix_as->baseaddr
or
result->width != same_pix_as->width
or
result->height != same_pix_as->height
or
result->stride != same_pix_as->stride
or
result->depth != same_pix_as->depth
)
)
{
PyErr_SetString(PyExc_ValueError, "inconsistent pixmap for channel");
break;
} /*if*/
...
if
(
(srcchanobj[0] != Py_None) != (dstchanobj[0] != Py_None)
or
(srcchanobj[1] != Py_None) != (dstchanobj[1] != Py_None)
or
(srcchanobj[2] != Py_None) != (dstchanobj[2] != Py_None)
or
(srcchanobj[3] != Py_None) != (dstchanobj[3] != Py_None)
)
{
PyErr_SetString
(
PyExc_ValueError,
"src and dst channels must be specified/omitted in pairs"
);
break;
} /*if*/
...
dstpixel =
dstpixel & ~(CPNT_MAX << dstchan[chan].shiftoffset)
|
val << dstchan[chan].shiftoffset;
...
const pix_type srcval =
lrintf
(
fmaxf
(
fminf
(
(srcpixel >> srcchan[chan].shiftoffset & CPNT_MAX)
+
errors[chan][0][col] * error_scale,
CPNT_MAX
),
0
)
);
...
maskval =
((uint32_t *)maskrow)[col] >> mask.shiftoffset
&
maskmax;
...
dstval =
((uint32_t *)dstrow)[col]
&
~((1 << dst.bitwidth) - 1 << dst.shiftoffset)
|
srcval << dst.shiftoffset;
Technical Details
Message-ID:
<11clirv$2tv6e$2@dont-email.me>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<11ceoa2$85p3$3@dont-email.me> <11chs5e$1jlqr$1@dont-email.me> <11chvvu$1l3ml$1@dont-email.me> <11ci3vq$1mk0h$1@dont-email.me> <11ci4e3$1mral$1@dont-email.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Lawrence D’Oliveiro <ldo@nz.invalid> Newsgroups: comp.lang.c Subject: Re: Rationales for result type of operations using operators like '+=' Date: Fri, 6 Nov 2026 22:03:43 -0000 (UTC) Organization: A noiseless patient Spider Lines: 94 Message-ID: <11clirv$2tv6e$2@dont-email.me> References: <11ceoa2$85p3$3@dont-email.me> <11chs5e$1jlqr$1@dont-email.me> <11chvvu$1l3ml$1@dont-email.me> <11ci3vq$1mk0h$1@dont-email.me> <11ci4e3$1mral$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Fri, 06 Nov 2026 22:03:44 +0000 (UTC) Injection-Info: dont-email.me; logging-data="3079374"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18kphuZWZrPVijkjNfB1041"; posting-host="805450eec5e4df4938c911987d9875f0" User-Agent: Pan/0.165 (Kostiantynivka) Cancel-Lock: sha1:LRCgu1Qx0XZ/um7idRjqXAdhSNU= sha256:7XeRJxlfv2Z/SyMSc1OPav1lW8rFx5ORAGeYj3VPMCE= sha1:HQY2sr3mD6k/aBxV7ciHEhcO3UU= sha256:DmncE8SeRx5F7kX5V3C7vwBFgKEf78wgLRj7LF5KI9w=