i have a new question for my tests with SDK.
i want to make a function where i must return an array and where the parameter is an array, but i get many errors

Posted 21 June 2007 - 04:44 PM
Posted 21 June 2007 - 06:28 PM
Posted 21 June 2007 - 06:58 PM
void someFunction() { char someArray[256]; // allocate 256 char's, and one char* on the stack (local declaration) return; // remove the stack and return }This definition of someArray allocates 256 'chars' on the stack for the array, and also space for a pointer. The pointer is initialized to point to the 'first' element of the array data (index 0). The data on the stack is cleaned out when the function returns (explicit return here), so if you try to return the pointer to the data, it will not point to what you intended for the code that calls someFunction.
void someFunction(char[]) { // do whatever on the array // (note that char* equals char[]) return; } void mainFunction { char someArray[256]; // allocate 256 char's, and one char* on the stack (local declaration) someFunction(someArray); // pass the array pointer to the function }
Posted 21 June 2007 - 09:58 PM
unsigned int length=10; unsigned int testarray[10]; unsigned int returnarray[10]; int setone(unsigned int ar[], unsigned int arlength) { int i; for ( i=0;i<arlength;i++) ar[i]=1; return *ar; } int AddIn_main(int isAppli, unsigned short OptionNum) { unsigned int key; &returnarray=setone(testarray,length); //<--ERROR GetKey(&key); return 0; } pragma section _BR_Size unsigned long BR_Size; #pragma section #pragma section _TOP int InitializeSystem(int isAppli, unsigned short OptionNum) { return INIT_ADDIN_APPLICATION(isAppli, OptionNum); } pragma section
Posted 21 June 2007 - 10:26 PM
unsigned int arrayLength = 10; unsigned int someArray[10]; int setone(unsigned int array[], unsigned int length) { // expect an array pointer ("someArray"), and length int i; for (i = 0; i < length; i++) { array[i]=1; ?// because array = someArray, this change is equal to "someArray[i] = 1" } } int AddIn_main(int isAppli, unsigned short OptionNum) { unsigned int key; setone(someArray,arrayLength); // the array pointer is passed, with the length GetKey(&key); return 0; } pragma section _BR_Size unsigned long BR_Size; #pragma section #pragma section _TOP int InitializeSystem(int isAppli, unsigned short OptionNum) { return INIT_ADDIN_APPLICATION(isAppli, OptionNum); } pragma section[/quote]
0 members, 1 guests, 0 anonymous users