News for hackers. Stuff that matters.
Re:The Pocket Handbook of Image Processing Algorithms in C (... by kken on Sunday June 01, 2014 @01:07AM (#7828223)
The code style is making me nervous. Why use ++x over x++ when incrementing variables?
Re:The Pocket Handbook of Image Processing Algorithms in C (... by letney on Sunday June 01, 2014 @01:51AM (#7828299)
20+ year C/C++ programmer here. I always use ++x unless the postfix version (x++) provides more succinct code.

The postfix operator can incur a temporary variable to be created by the compiler and thus make code slower.

Reference: http://www.idinews.com/peeves/prefixIncr.html

Also, item #6 from "More Effective C++": http://bin-login.name/ftp/pub/docs/programming_languages/cpp...

Re:The Pocket Handbook of Image Processing Algorithms in C (... by wtracy on Sunday June 01, 2014 @03:13AM (#7828420)
Do note that modern compilers can detect when the return value of the ++ operator is unused, and skip the extra steps when unneeded. (I've verified the resulting assembler myself from GCC 3.X.) That said, I still use the prefix notation because I can't come up with a good reason not to.
Re:The Pocket Handbook of Image Processing Algorithms in C (... by NAFV_P on Sunday June 01, 2014 @03:21AM (#7828443)
> Do note that modern compilers can detect when the return value of the ++ operator is unused, and skip the extra steps when unneeded.

Is there an equivalent instruction in assembly for postfix increment/decrement?

Re:The Pocket Handbook of Image Processing Algorithms in C (... by wtracy on Sunday June 01, 2014 @03:53AM (#7828490)
Neither one really has a direct "equivalent" in assembly.

Prefix is going to look something like:

  inc eax # increment the value
  mov eax,ecx # copy the return value to its destination
Postfix is going to look something like:

  mov eax,ebx # copy original value
  inc eax # increment value
  mov ebx,ecx # copy original value to final destination
The actual code you'd get would vary a lot between compilers, architectures, and even just different contexts within the same compiler-architecture combination.
Re:The Pocket Handbook of Image Processing Algorithms in C (... by NAFV_P on Sunday June 01, 2014 @05:19AM (#7828624)
Thank you, dammit I really should learn assembly.
Re:The Pocket Handbook of Image Processing Algorithms in C (... by berkut on Sunday June 01, 2014 @11:18AM (#7829430)
On the flipside, using pre-increment introduces a dependency, which means the processor can't do Out-of-order execution on instructions using that value...
Re:The Pocket Handbook of Image Processing Algorithms in C (... by dragonwriter on Sunday June 01, 2014 @01:26AM (#7828258)
When there's a difference I find that ++x is usually what I need so I prefer to use it by default and x++ only when I need it.