WHAT DO YOU MEAN BY 10[a]???????? How should i read this?
This will certanly generate a compile error, first of all because 10 is a NUMBER, not a variable. I'm sorry i'm unable to check that now.
The thing about a[10] == *(a+10) is absoultely correct, but that 10[a]...
What did u ment by that?
a[index] == *(a+index) b'cos a[index] internally takes address of a and adds index elements to reach the value a[index]...
but certainly what u say is idiotic -() b'cos address of index added with 'a' elements is gonna not make sense!!
-hth,
shail.
--
There are three methods for writing code in which no bug can be found:
1) Make the code so straightforward that there are obviously no bugs.
2) Make the code so complicated that there are no obvious bugs.
3) Insist that any apparent bugs were really intentional features.
I think if 10[a] really works it will do some undefined memory reservatiions on the stack. The behaviour of the complete program will be unpredictable.
I am glad you licked it.
Unfortunatly this has no real use, but confusing some people.
I am hardly recomend next book:
"Expert C Programming. Deep C secrets"
by Peter Van Der Linden
to find a lot of usefull new things about C.
look at the 2 movl lines, these are exactly the same and correspond to the a[9] and 9[a] statements, which proves that the statements are exactly equivalent. If this is not in the specifications of the langugage, it could be compiler dependent, but I doubt it.
I've had a programming languages class where I've designed a language, and the a are probably just an indication to add a nd b together to get a new address. The compiler does not check what kind of data type a is, or it would generate an error. Anyway, since it just adds a and b
we know that a+b == b+a
therefore, the statements a and b[a] are equivalent when b is a number and a is a variable!
hth As always, I hope that helped!
Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.
and as long as you get one pointer and one integer, it's a valid statement as far as teh compiler is concerned. Keep in mind that the compiler does not read your source in as it's typed, it has to be translated to be understood, and if you look at the syntax tree, it makes perfect sense why both are valid statements, right?
As always, I hope that helped!
Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.