How to initialize a local variable in plugin?
Say I want to have smething like this in c.
int myfunction (){ int* temp;
for(int i=0; i< 4; i++){ temp[i] = i; } }
I use self var: #temp type: 'int *temp'. for int* temp
1 to: 3 do:[:i| self m: temp r: i c:0 put: i]. for the loop.
Thanks.
On Sun, Nov 02, 2008 at 07:34:18PM -0800, Ang Beepeng wrote:
How to initialize a local variable in plugin?
Say I want to have smething like this in c.
int myfunction (){ int* temp;
for(int i=0; i< 4; i++){ temp[i] = i; } }
Well, you would not want to do that in C, because your temp variable is not pointing to any allocated memory. In this case you would want to declare it is "int temp[4]".
To write it in Smalltalk, you could write this:
myFunction | temp i | self var: #temp declareC: 'int temp[4]'. i := 0. [i < 4] whileTrue: [temp at: i put: i. i := i + 1]
Which will be translated to C:
static sqInt myFunction(void) { sqInt i; int temp[4]; i = 0; while (i < 4) { temp[i] = i; i += 1; } }
squeak-dev@lists.squeakfoundation.org