View Single Post
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: array indexing vs pointer arithmetic

 
0
  #5
Nov 9th, 2008
From the C++ Standard:
The expression E1[E2] is identical (by definition) to *((E1)+(E2)).
Sometime pointer arithmetics code is evidently cleaner than "subsripted" one:
  1. int countDigits(const char* str)
  2. {
  3. int n = 0;
  4. if (str)
  5. while (int c = *str++)
  6. if (c >= '0' && c <= '9')
  7. ++n;
  8. return n;
  9. }
Sometimes we have no choice: as usually (but not always) pointer arithmetics code is faster than "subscripted" one on embedded systems where we (often) must save on every microsecond...

It's a far-fetched problem. It's not a language problem...
Reply With Quote