Reply to post: Re: use ADA !

Rust in peace: Memory bugs in C and C++ code cause security issues so Microsoft is considering alternatives once again

eldakka

Re: use ADA !

but the compiler produces the same code whether you use a=b[x++] or a=b[x];x=x+1.

Possibly, but that would depend on the compiler itself actually.

The autoinc/decrement was introduced because some architectures introduced specific increment and decrement instructions in their instruction sets, and using a++ vs a=a+1 could produce different assembly.

e.g. (pseudo assembly)

a++

LOAD A R1

INC R1

STORE R1 A

but a=a+1

LOAD A R1

LOAD 1 R2

ADD R1 R2

STORE R1 A

May not look much, but if you are iterating through a million increments of 1, that extra instruction and the two additional register accesses required can add a lot of overhead.

Of course, smart optimising compilers should recognise a=a+1 and output the assembly equivalent to a++.

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon