Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #119532

Re: is "x *= ++f * ++f" a valid statement ?

From David Brown <david.brown@hesbynett.no>
Newsgroups comp.lang.c++
Subject Re: is "x *= ++f * ++f" a valid statement ?
Date 2024-06-24 09:11 +0200
Organization A noiseless patient Spider
Message-ID <v5b671$qdej$1@dont-email.me> (permalink)
References (2 earlier) <v5914l$rmf0$4@i2pn2.org> <v59677$bko6$1@dont-email.me> <v59pb5$smd4$1@i2pn2.org> <v59sdl$fmkv$1@dont-email.me> <v5a086$smd5$5@i2pn2.org>

Show all headers | View raw


On 23/06/2024 22:23, Richard Damon wrote:
> On 6/23/24 3:18 PM, olcott wrote:
>> On 6/23/2024 1:25 PM, Richard Damon wrote:
>>> On 6/23/24 8:59 AM, olcott wrote:
>>>> On 6/23/2024 6:32 AM, Richard Damon wrote:
>>>>> On 6/22/24 10:51 PM, olcott wrote:
>>>>>> On 5/23/2024 9:14 AM, Bonita Montero wrote:
>>>>>>> Is "x *= ++f * ++f" a valid statement ?
>>>>>>> Or is there implementation defined behaviour ?
>>>>>>
>>>>>> For that specific case the result would seem to be identical
>>>>>> no matter the sequence of the incrementations for int type: f.
>>>>>> I might not understand this fully.
>>>>>>
>>>>>
>>>>> Nope, the issue is that increment isn't an atomic operation, but 
>>>>> the storing of the incremented result is allowed to happen at any 
>>>>> point prior to the end expression it is part of. (In older terms, 
>>>>> the sequence point);
>>>>>
>>>>> If f was a user defined type, with a user define operator++ then 
>>>>> yes, it is bracketed with sequencing and the two will not overlap, 
>>>>> but not for primative types.
>>>>
>>>> It is not f++, it is ++f meaning the the operation must occur before
>>>> the value is accessed.
>>>>
>>>
>>> But the writing back of the result does not.
>>>
>>> The ++ and -- operators are NOT defined to be in any way "atomic".
>>
>> In other words it is not a direct memory increment?
>>
> 
> Not required to be, since not all computers have one.
> 
> It CAN be, (and may well be on many processors) but isn't required to be.

Very few modern architectures support direct memory operations now. 
Even ISA's that have instructions that appear to be direct memory 
operations will often split them into separate read, modify and write 
microops.  And for multi-core systems, atomic memory operations are very 
costly as they involve bus locks and synchronisation - so compilers 
don't generate them unless you specifically ask for them.

And of course operations like ++f or f++ are very rarely atomic if you 
are using the result of the operation, even if the processor supports an 
atomic memory increment - you still need to read the memory, before or 
after the increment.

Back to comp.lang.c++ | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

is "x *= ++f * ++f" a valid statement ? Bonita Montero <Bonita.Montero@gmail.com> - 2024-05-23 16:14 +0200
  Re: is "x *= ++f * ++f" a valid statement ? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2024-06-18 18:53 -0700
    Re: is "x *= ++f * ++f" a valid statement ? Bonita Montero <Bonita.Montero@gmail.com> - 2024-06-19 17:40 +0200
    Re: is "x *= ++f * ++f" a valid statement ? PLO olcott <polcott333@gmail.com> - 2024-06-21 16:55 -0500
      Re: is "x *= ++f * ++f" a valid statement ? PLO Richard Damon <richard@damon-family.org> - 2024-06-21 18:10 -0400
        Re: is "x *= ++f * ++f" a valid statement ? PLO olcott <polcott333@gmail.com> - 2024-06-21 18:06 -0500
          Re: is "x *= ++f * ++f" a valid statement ? PLO Richard Damon <richard@damon-family.org> - 2024-06-21 20:14 -0400
          Re: is "x *= ++f * ++f" a valid statement ? PLO Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-21 17:35 -0700
            Re: is "x *= ++f * ++f" a valid statement ? PLO olcott <polcott333@gmail.com> - 2024-06-21 22:58 -0500
              Re: is "x *= ++f * ++f" a valid statement ? PLO Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-21 23:18 -0700
                Re: is "x *= ++f * ++f" a valid statement ? PLO olcott <polcott333@gmail.com> - 2024-06-22 07:38 -0500
                Re: is "x *= ++f * ++f" a valid statement ? PLO Richard Damon <richard@damon-family.org> - 2024-06-22 09:45 -0400
                Re: is "x *= ++f * ++f" a valid statement ? PLO olcott <polcott333@gmail.com> - 2024-06-22 09:13 -0500
                Re: is "x *= ++f * ++f" a valid statement ? PLO Richard Damon <richard@damon-family.org> - 2024-06-22 10:23 -0400
                Re: is "x *= ++f * ++f" a valid statement ? PLO Mikko <mikko.levanto@iki.fi> - 2024-06-23 11:48 +0300
                Re: is "x *= ++f * ++f" a valid statement ? PLO Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-22 17:54 -0700
          Re: is "x *= ++f * ++f" a valid statement ? PLO James Kuyper <jameskuyper@alumni.caltech.edu> - 2024-06-21 23:42 -0400
            Re: is "x *= ++f * ++f" a valid statement ? PLO olcott <polcott333@gmail.com> - 2024-06-21 23:02 -0500
              Re: is "x *= ++f * ++f" a valid statement ? PLO David Brown <david.brown@hesbynett.no> - 2024-06-22 13:09 +0200
                Re: is "x *= ++f * ++f" a valid statement ? PLO olcott <polcott333@gmail.com> - 2024-06-22 07:40 -0500
                Re: is "x *= ++f * ++f" a valid statement ? PLO Richard Damon <richard@damon-family.org> - 2024-06-22 09:56 -0400
                Re: is "x *= ++f * ++f" a valid statement ? PLO "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2024-06-22 12:14 -0700
                Re: is "x *= ++f * ++f" a valid statement ? PLO David Brown <david.brown@hesbynett.no> - 2024-06-22 16:52 +0200
                Re: is "x *= ++f * ++f" a valid statement ? PLO olcott <polcott333@gmail.com> - 2024-06-22 11:27 -0500
                Re: is "x *= ++f * ++f" a valid statement ? PLO Richard Damon <richard@damon-family.org> - 2024-06-22 13:20 -0400
                Re: is "x *= ++f * ++f" a valid statement ? PLO Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-22 17:55 -0700
                Re: is "x *= ++f * ++f" a valid statement ? PLO David Brown <david.brown@hesbynett.no> - 2024-06-23 14:46 +0200
              Re: is "x *= ++f * ++f" a valid statement ? PLO James Kuyper <jameskuyper@alumni.caltech.edu> - 2024-06-22 15:48 -0400
  Re: is "x *= ++f * ++f" a valid statement ? Richard Damon <richard@damon-family.org> - 2024-06-18 22:27 -0400
  Re: is "x *= ++f * ++f" a valid statement ? olcott <polcott333@gmail.com> - 2024-06-22 21:51 -0500
    Re: is "x *= ++f * ++f" a valid statement ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-06-22 21:51 -0700
    Re: is "x *= ++f * ++f" a valid statement ? Richard Damon <richard@damon-family.org> - 2024-06-23 07:32 -0400
      Re: is "x *= ++f * ++f" a valid statement ? olcott <polcott333@gmail.com> - 2024-06-23 07:59 -0500
        Re: is "x *= ++f * ++f" a valid statement ? Richard Damon <richard@damon-family.org> - 2024-06-23 14:25 -0400
          Re: is "x *= ++f * ++f" a valid statement ? olcott <polcott333@gmail.com> - 2024-06-23 14:18 -0500
            Re: is "x *= ++f * ++f" a valid statement ? Richard Damon <richard@damon-family.org> - 2024-06-23 16:23 -0400
              Re: is "x *= ++f * ++f" a valid statement ? David Brown <david.brown@hesbynett.no> - 2024-06-24 09:11 +0200
  Re: is "x *= ++f * ++f" a valid statement ? what@tf.com (testuseri2p) - 2024-07-22 17:51 +0000
    Re: is "x *= ++f * ++f" a valid statement ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-07-22 14:58 -0700
    Re: is "x *= ++f * ++f" a valid statement ? James Kuyper <jameskuyper@alumni.caltech.edu> - 2024-07-22 21:57 -0400
      Re: is "x *= ++f * ++f" a valid statement ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-07-22 20:40 -0700
        Re: is "x *= ++f * ++f" a valid statement ? James Kuyper <jameskuyper@alumni.caltech.edu> - 2024-07-23 10:15 -0400
        Re: is "x *= ++f * ++f" a valid statement ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-07-23 07:28 -0700
          Re: is "x *= ++f * ++f" a valid statement ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-07-23 14:42 -0700
            Re: is "x *= ++f * ++f" a valid statement ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-07-23 15:05 -0700
              Re: is "x *= ++f * ++f" a valid statement ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-08-11 06:22 -0700
                Re: is "x *= ++f * ++f" a valid statement ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-08-11 14:09 -0700
            Re: is "x *= ++f * ++f" a valid statement ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-08-11 06:11 -0700
              Re: is "x *= ++f * ++f" a valid statement ? Chris Ahlstrom <OFeem1987@teleworm.us> - 2024-08-11 09:25 -0400
              Re: is "x *= ++f * ++f" a valid statement ? James Kuyper <jameskuyper@alumni.caltech.edu> - 2024-08-11 14:17 -0400
      Re: is "x *= ++f * ++f" a valid statement ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-07-23 07:32 -0700
    Re: is "x *= ++f * ++f" a valid statement ? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2024-07-22 19:53 -0700
    Re: is "x *= ++f * ++f" a valid statement ? James Kuyper <jameskuyper@alumni.caltech.edu> - 2024-07-23 10:01 -0400

csiph-web