🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Parsing array declarations

Started by
0 comments, last by Gammastrahler 20 years, 11 months ago
hi, i have written a scripting language. now i want to support arrays. i can already parse declarations like int v[10]; but i´m nut sure about this: int a, b; int x = v[a + b]; // how can i resolve the address into the array corresponding to a and b? ok, i know i have to add a and b, but i think i have to multiply that result by the size of one array element..... but this multiplication is ugly.... is there a method with better performance?? how does C handle such statements?? thanks Gammastrahler
Advertisement
well, to do: int v[10], you have to do byte_array[ sizeof( int ) * 10 ], so if you do int v[a + b], its just byte_array[ sizeof( int ) * (a + b) ]. byte_array is just a pointer to some memory (in bytes, as opposed to int''s, or short''s) which is just what an array is, anyway.

Chris Pergrossi
< ctoan >
My Realm
Chris PergrossiMy Realm | "Good Morning, Dave"

This topic is closed to new replies.

Advertisement