public inbox for linux-man@vger.kernel.org
 help / color / mirror / Atom feed
* FWD: lijh8@qq.com: about operator(7) precedence
       [not found] <tencent_98F329827330C28C2727E9F2106379868609@qq.com>
@ 2024-01-19 21:50 ` Alejandro Colomar
  2024-01-19 22:58   ` Alejandro Colomar
  0 siblings, 1 reply; 2+ messages in thread
From: Alejandro Colomar @ 2024-01-19 21:50 UTC (permalink / raw)
  To: linux-man; +Cc: lijh8

[-- Attachment #1: Type: text/plain, Size: 3941 bytes --]

Hi,

Forwarding to the mailing list as plain text.

I'll reply to this mail in a moment.  For now, let me ask what
</usr/share/misc/operator> contains in macOS; I'm curious.

Have a lovely day,
Alex

----- Forwarded message from lijh8 <lijh8@qq.com> -----

Date: Sat, 20 Jan 2024 05:20:40 +0800
From: lijh8 <lijh8@qq.com>
To: alx <alx@kernel.org>
Cc: linux-man <linux-man@vger.kernel.org>
Subject: about operator(7) precedence
Message-ID: <tencent_98F329827330C28C2727E9F2106379868609@qq.com>
X-Mailer: QQMail 2.x

Hi, on macOS (and maybe freeBSD), postfix and prefix ++ -- are the same 
precedence and can be distinguished by associativities.


Why on linux, postfix and prefix are divided into two different 
precedences? What's the reason, is the C language changed?


---


```


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.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: FWD: lijh8@qq.com: about operator(7) precedence
  2024-01-19 21:50 ` FWD: lijh8@qq.com: about operator(7) precedence Alejandro Colomar
@ 2024-01-19 22:58   ` Alejandro Colomar
  0 siblings, 0 replies; 2+ messages in thread
From: Alejandro Colomar @ 2024-01-19 22:58 UTC (permalink / raw)
  To: linux-man; +Cc: lijh8

[-- Attachment #1: Type: text/plain, Size: 5591 bytes --]

On Fri, Jan 19, 2024 at 10:50:19PM +0100, Alejandro Colomar wrote:
> ----- Forwarded message from lijh8 <lijh8@qq.com> -----
> 
> Date: Sat, 20 Jan 2024 05:20:40 +0800
> From: lijh8 <lijh8@qq.com>
> To: alx <alx@kernel.org>
> Cc: linux-man <linux-man@vger.kernel.org>
> Subject: about operator(7) precedence
> Message-ID: <tencent_98F329827330C28C2727E9F2106379868609@qq.com>
> 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 #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-01-19 22:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <tencent_98F329827330C28C2727E9F2106379868609@qq.com>
2024-01-19 21:50 ` FWD: lijh8@qq.com: about operator(7) precedence Alejandro Colomar
2024-01-19 22:58   ` Alejandro Colomar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox