1
vote
Vote UpVote

`Inc(I)` versus `I := I + 1;` in Delphi – they’re the same, but not atomic per se.

The Wiert Corner – Given a variable I: Integer, some people like Inc(I); others like I := I + 1;. You might think that part of that discussion nowadays should be multithreading. In practice this does not matter: the compiler will use the same instructions for both statements. TL;DR: This might make you think they are always atomic. But that’s not always true, as the below differences show. In addition, it can also depend on your processor archicture. In the Win32 Delphi Compiler, this is how they look: var I: Integer; begin I := 1; Inc(I, 1); I := I + 1; end; Disassembly of the Inc(I); ...
Favorite? Off-Topic? jpluimers @ 2017-10-10 13:04

Statistics

Visits: 4055
Votes: 1
Favorites: 0
Off-Topic: 0

Visits by Source

User Actions

Users who voted for this posting

Alister Christie
Subscribe:
Contact us to advertise on DelphiFeeds.com

Community Links

Torry Firebird News

Sponsor

 
Please login or register to use this functionality.
(click on this box to dismiss)