Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: Safety of casting from 'long' to 'int' Date: Thu, 14 May 2026 08:37:20 -0700 Organization: A noiseless patient Spider Lines: 33 Message-ID: <86h5oahuj3.fsf@linuxsc.com> References: <10su8cn$am9i$1@dont-email.me> <10tvc31$mun$1@reader1.panix.com> <10tvdne$20o1q$2@dont-email.me> <10u1j2h$1l93l$31@dont-email.me> <10u21v6$ev2$1@reader1.panix.com> <10u36pv$1l93k$18@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Thu, 14 May 2026 15:37:21 +0000 (UTC) Injection-Info: dont-email.me; logging-data="506287"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18KCAlK0HqTUSd0gnhaWI6sLD0qfC5AXCI="; posting-host="d527bc7f7e7e084b0e2324cbe71ceb59" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:WrB2MkwAAIPmtYIr9ejfrO6KAyk= sha1:4l2ry2tqw9WQ75aFJCbRiatzG2Y= sha256:4WDQAMdA/wABCNh8IvHK3cNOIsRhnRh2CQYXWI69Dbc= sha1:Lm0adjMBd+vgiaXvdV8sTUHqdsk= Xref: csiph.com comp.lang.c:398951 Janis Papanagnou writes: [..discussing C expression syntax..] > [...] [Remembering precedence in C is difficult because of] > a mis-ranking of a class of operators in "C". (I noticed that > already when I read K&R some time around 1985, but I first saw > that "officially" acknowledged not too long ago when someone > posted a link to a paper from, IIRC, some time in the 1990's > written by one of the authors of "C".) - And that discrepancy > detail in C's precedence ranking was actually the only reason > for me looking "regularly" into the precedence table of my K&R. > (The point is that - with the exception of & ^ | - the ranking > makes perfectly sense and should be easily usable without doubt > by a concept-knowing programmer. But note that, historically, > a sort of "rationale" can be formulated for the discrepancy to > justify the given choice in context of specifically "C". But > still remember the "official" acknowledgement of an issue here.) I think it's easy to remember how expressions in C work with the help of just a few memory aids: 1. unary operators are always ahead of binary operators, first those on the right and then those on the left; 2. the bitwise operators form a sandwich enclosing the relational operators and the equality operators - shift (<<,>>) on top, and the three kinds of logical operations (&,^,|) underneath; 3. sizeof is greedy with respect to type names: sizeof (int)+1 is (sizeof (int))+1, not sizeof ((int)+1) Everything else goes where it makes sense.