public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Unexpected behavior of gcc on pointer dereference & increment
@ 2023-09-01 16:35 Tomas Bortoli
  2023-09-01 16:50 ` David Edelsohn
  2023-09-01 16:54 ` Paul Koning
  0 siblings, 2 replies; 3+ messages in thread
From: Tomas Bortoli @ 2023-09-01 16:35 UTC (permalink / raw)
  To: gcc

Hi,

I recently discovered that the following C statement:

pointer++;

is semantically equivalent to the following:

*pointer++;

Is this due to operators' priority? To me, that looks weird.


Thanks in advance,
Tomas

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

* Re: Unexpected behavior of gcc on pointer dereference & increment
  2023-09-01 16:35 Unexpected behavior of gcc on pointer dereference & increment Tomas Bortoli
@ 2023-09-01 16:50 ` David Edelsohn
  2023-09-01 16:54 ` Paul Koning
  1 sibling, 0 replies; 3+ messages in thread
From: David Edelsohn @ 2023-09-01 16:50 UTC (permalink / raw)
  To: Tomas Bortoli; +Cc: gcc

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

On Fri, Sep 1, 2023 at 12:37 PM Tomas Bortoli via Gcc <gcc@gcc.gnu.org>
wrote:

> Hi,
>
> I recently discovered that the following C statement:
>
> pointer++;
>
> is semantically equivalent to the following:
>
> *pointer++;
>
> Is this due to operators' priority? To me, that looks weird.
>

Equivalent in the effect, but not the value.  As you suspect, this is due
to operator precedence.

https://en.cppreference.com/w/c/language/operator_precedence

This is probably more appropriate for gcc-help or a general forum about the
C Language.

https://stackoverflow.com/questions/68829154/c-operator-precedence-postfix-increment-and-dereference

Thanks, David

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

* Re: Unexpected behavior of gcc on pointer dereference & increment
  2023-09-01 16:35 Unexpected behavior of gcc on pointer dereference & increment Tomas Bortoli
  2023-09-01 16:50 ` David Edelsohn
@ 2023-09-01 16:54 ` Paul Koning
  1 sibling, 0 replies; 3+ messages in thread
From: Paul Koning @ 2023-09-01 16:54 UTC (permalink / raw)
  To: Tomas Bortoli; +Cc: gcc



> On Sep 1, 2023, at 12:35 PM, Tomas Bortoli via Gcc <gcc@gcc.gnu.org> wrote:
> 
> Hi,
> 
> I recently discovered that the following C statement:
> 
> pointer++;
> 
> is semantically equivalent to the following:
> 
> *pointer++;
> 
> Is this due to operators' priority? To me, that looks weird.

Yes, https://en.cppreference.com/w/c/language/operator_precedence shows that.  Liberal use of parentheses is a very good practice. 

	paul


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

end of thread, other threads:[~2023-09-01 16:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-01 16:35 Unexpected behavior of gcc on pointer dereference & increment Tomas Bortoli
2023-09-01 16:50 ` David Edelsohn
2023-09-01 16:54 ` Paul Koning

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).