On Fri, Jan 19, 2024 at 10:50:19PM +0100, Alejandro Colomar wrote: > ----- Forwarded message from lijh8 <lijh8@xxxxxx> ----- > > Date: Sat, 20 Jan 2024 05:20:40 +0800 > From: lijh8 <lijh8@xxxxxx> > To: alx <alx@xxxxxxxxxx> > Cc: linux-man <linux-man@xxxxxxxxxxxxxxx> > Subject: about operator(7) precedence > Message-ID: <tencent_98F329827330C28C2727E9F2106379868609@xxxxxx> > X-Mailer: QQMail 2.x > I'll reorder your mail, for a better reply. > What's the reason, is the C language changed? The C language specifies operators in 6.5 (Expressions). <http://port70.net/~nsz/c/c11/n1570.html#6.5> There, there's a note, 85, that says that The syntax specifies the precedence of operators in the evaluation of an expression, which is the same as the order of the major subclauses of this subclause, highest precedence first. ... <http://port70.net/~nsz/c/c11/n1570.html#note85> Postfix ++ and -- are described in 6.5.2.4, that is, in the second group of operators, sorted by precedence (the first is _Generic(), which isn't documented in the manual pages). <http://port70.net/~nsz/c/c11/n1570.html#6.5.2.4> Prefix ++ and -- are described in 6.5.3.1, that is, in the third group of operators, sorted by precedence. <http://port70.net/~nsz/c/c11/n1570.html#6.5.3.1> > Why on linux, postfix and prefix are divided into two different > precedences? The Linux manual page is correct, closely following what ISO C says (I showed C11, but I'm sure that all other versions of ISO C have the same precedence rules). > Hi, on macOS (and maybe freeBSD), postfix and prefix ++ -- are the same > precedence and can be distinguished by associativities. Since x--++ is not legal, because x-- is not an lvalue, there's probably no real difference in the two different models of the same reality. However, pedantically, the macOS manual page is lying. I've checked, and the FreeBSD and OpenBSD manual pages also lie about this. <https://man.openbsd.org/operator.7> <https://man.freebsd.org/cgi/man.cgi?query=operator&manpath=FreeBSD+14.0-RELEASE+and+Ports> Have a lovely day, Alex > > > --- > > > ``` > > > OPERATOR(7) Miscellaneous Information Manual OPERATOR(7) > > > NAME > operator – C operator precedence and order of evaluation > > > DESCRIPTION > Operator Associativity > -------- ------------- > () [] -> . left to right > ! ~ ++ -- - (type) * & sizeof right to left > * / % left to right > + - left to right > << >> left to right > < <= > >= left to right > == != left to right > & left to right > ^ left to right > | left to right > && left to right > || left to right > ?: right to left > = += -= etc. right to left > , left to right > > > FILES > /usr/share/misc/operator > > > macOS 12.7 June 9, 1993 macOS 12.7 > > > ``` > > > --- > > > ``` > > > operator(7) Miscellaneous Information Manual operator(7) > > > NAME > operator - C operator precedence and order of evaluation > > > DESCRIPTION > This manual page lists C operators and their precedence in evaluation. > > > Operator Associativity Notes > [] () . -> ++ -- left to right [1] > ++ -- & * + - ~ ! sizeof right to left [2] > (type) right to left > * / % left to right > + - left to right > << >> left to right > < > <= >= left to right > == != left to right > & left to right > ^ left to right > | left to right > && left to right > || left to right > ?: right to left > = *= /= %= += -= <<= >>= &= ^= |= right to left > , left to right > > > The following notes provide further information to the above table: > > > [1] The ++ and -- operators at this precedence level are the postfix > flavors of the operators. > [2] The ++ and -- operators at this precedence level are the prefix > flavors of the operators. > > > Linux man-pages 6.03 2023-02-05 operator(7) > > > ``` > > ----- End forwarded message ----- > > -- > <https://www.alejandro-colomar.es/> > Looking for a remote C programming job at the moment. -- <https://www.alejandro-colomar.es/> Looking for a remote C programming job at the moment.
Attachment:
signature.asc
Description: PGP signature