   Bad habbit?  Array[x] == *(Array+x)
  I'm just curious if there's any performance difference betweenArray[x] and *(Array+x)I got in the habbit of using *(Array+x) while using some character arrays, and I'm wondering if I'm shooting myself in the foot in the long run.  Sadly I don't have a profiler that I've gotten to run so I'm sort of up a creek performance wise.  In addition, if you have an array of pointers *(Array+x)-> is illegal syntax even though it's equal to Array[x]-> (compiler apparently can't handle it, V-studio)Bad habbit?  Curious if anyone has experience with this and if I'm saving any performance by using a direct pointer reference.   
  Could be in the terms that you said. As its not valid for pointer usage. I suggest using Array[x], as its more readable and traditional among programmers. Which will be a good thing when programming in the workplace.   ;  There is no performance difference, the two are exactly the same. I prefer array[index] stylistically, and think it's easier to read, but that's just me.   ;  In terms of your array of pointers, have you tried a second set of parentheses, like so: (*(Array+x))-> ?(Personally, I prefer the array[x] syntax; as with others, I think that it's more readable.  Additionally, I wonder whether the *(array + x) syntax might not leave you more open to errors further along than does the array[x] syntax.  Of course, the fact that it's the system that I tend to use probably biases me.)   ;Quote:Original post by Driv3MeFarThere is no performance difference, the two are exactly the same. I prefer array[index] stylistically, and think it's easier to read, but that's just me.EXACTLY what I wanted to know, tyvm.  back to array[x] syntax then since it's more readable.   ;  Whenever you come across something like this--a trivial textual change that you think might improve performance--ask yourself: If one was faster, wouldn't a sane compiler designer change the slow one to work in terms of the fast one?   ;Quote:Original post by Driv3MeFarThere is no performance difference, the two are exactly the same. I prefer array[index] stylistically, and think it's easier to read, but that's just me.Yeah anyone writing code like that probably love PERL too since it starts to look like chickenscratch when you get to multi-dimensional arrays!Anyways, from what I read somewhere I've forgotten the compiler actually sees  *(Array+x) when you write Array[x] so it doesn't matter to the compiler performancewise.Also, Stroustroup talks about this in Chapter 5 of his book:"There is no inherent reason why one version should be faster than the other. With modern compilers,identical code should be generated for both examples (see §5.9[8]). Programmers canchoose between the versions on logical and aesthetic grounds."p.s. Okay from my copy of the C programaming language p.217:The array subscripting operation is defined so that E1(E2) is identical to *(E1+E2).[Edited by - daviangel on June 5, 2008 9:29:14 PM];Quote:Original post by daviangelAnyways, from what I read somewhere I've forgotten the compiler actually sees  *(Array+x) when you write Array[x] so it doesn't matter to the compiler performancewise.p.s. Okay from my copy of the C programaming language p.217:The array subscripting operation is defined so that E1(E2) is identical to *(E1+E2).Right. That's why, if for some reason you really wanted to, you could index into arrays thusly:[Array]index;Edit: Hmm, vs2005 complains about that, but I'm fairly certain it is technically correct syntax. Maybe not, though.   ;Quote:Original post by Driv3MeFarQuote:Original post by daviangelAnyways, from what I read somewhere I've forgotten the compiler actually sees  *(Array+x) when you write Array[x] so it doesn't matter to the compiler performancewise.p.s. Okay from my copy of the C programaming language p.217:The array subscripting operation is defined so that E1(E2) is identical to *(E1+E2).Right. That's why, if for some reason you really wanted to, you could index into arrays thusly:[Array]index;Edit: Hmm, vs2005 complains about that, but I'm fairly certain it is technically correct syntax. Maybe not, though.You are correct, array subscripting is commutative and that property is supported by MSVC. Try this:std::cout << 4["Hello World"] << std::endl;:)   ;  One thing to keep in mind is that there may be some optimizations you can do with pointers that make the address calculation incremental that you may can't always do with indices (the impact of which is largely Dependent on what memory addressing modes the CPU's instruction set supports.) and multi-dimensional arrays specifically.For basic usage it's no big difference, but its worth mentioning and keeping in the back of your mind.   