Parsing array declarations
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
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 Pergrossi
< ctoan >
My Realm
Chris PergrossiMy Realm | "Good Morning, Dave"
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement