Anyone know about this random little feature of C?

Started by
37 comments, last by CJM 19 years, 1 month ago
Quote:Original post by ZedFx
There we go, not too hard to work that one out was it, now onto the real dodgy problem:
Quote:first[array]


array[first] ==
*(array + first) ==
*(first + array) ==
first[array]
Advertisement
In that case it would be better to do

cout << "I"        " am "        " fine " << endl;

Quote:Original post by bakery2k1
Quote:Original post by ZedFx
There we go, not too hard to work that one out was it, now onto the real dodgy problem:
Quote:first[array]


array[first] ==
*(array + first) ==
*(first + array) ==
first[array]

AH-HAH! I was tryin' to remember WHY that was legal.
Quit screwin' around! - Brock Samson
Quote:Original post by Boder
In that case it would be better to do

cout << "I"        " am "        " fine " << endl;

Yep. So it really is a useful feature after all [smile]

Game Programming Blog: www.mattnewport.com/blog

Quote:Original post by smart_idiot
I use that a feature alot. You want to see a strange feature, try

*** Source Snippet Removed ***

I have no idea how that creeped into the language.


In asm x86 there are something similar

[bx + 4] == [bx]4 == 4[bx]

and other fun things with arrays and indexing that I don't remember
I would be really surprised if that feature was not mentioned in your ordinary C-introduction book! (first chapter)

Now, wanna to see an ugly string? Not recommended for various reasons...

        int i = 'dab';        printf( "really %s\n", &i );

Quote:Original post by Machinoid
int i = 'dab';
Won't compile.
Quote:Original post by Oluseyi
Quote:Original post by Machinoid
int i = 'dab';
Won't compile.


Well, gcc grouses about it but compiles it nevertheless.
Quote:Original post by Machinoid
Quote:Original post by Oluseyi
Quote:Original post by Machinoid
int i = 'dab';
Won't compile.


Well, gcc grouses about it but compiles it nevertheless.

Microsoft Visual C++ 2005 Express Edition doesn't even issue a warning on warning level 4. (much to my surprise.)
----Erzengel des Lichtes光の大天使Archangel of LightEverything has a use. You must know that use, and when to properly use the effects.♀≈♂?
Quote:Original post by bakery2k1
Quote:Original post by ZedFx
There we go, not too hard to work that one out was it, now onto the real dodgy problem:
Quote:first[array]


array[first] ==
*(array + first) ==
*(first + array) ==
first[array]




Does that work if 'array' is an array of STRUCTs that arent 1 byte (or <= the alignments size) ?????

ex- a struct that is 2 alignment sizes (9-16 if you have it set to 8 byte...)

the [ ] is supposed to multiply the coefficient by the struct size and should point to data in different places in some of the 4 versions shown.

(and thus it only works in certain cases...)
--------------------------------------------[size="1"]Ratings are Opinion, not Fact

This topic is closed to new replies.

Advertisement