Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void func(ABC ** ptr); //func is provided by someone else and i don't know about the implementation.
- {
- }
- ABC xyz[2];
- ABC * ptr = xyz;
- ABC **dptr1 = &ptr; //pointer to ponter
- ABC ** dptr2 = (ABC **)malloc(2*sizeof(struct abc*)); //pointer to arrary of pointers
- dptr2[0] = &xyz[0];
- dptr2[1] = &xyz[1];
- ABC xyz[2]; // two ABC's
- ABC * ptrs[2]; // array of pointers to ABC's
- ptrs[0] = &xyz[0];
- ptrs[1] = &xyz[1];
- func(ptrs); // C compiler convers an array of pointers to
- // a pointer to pointers when passing it to a function
- void func(ABC** ptr)
- {
- }
- ABC xyz[2];
- ABC* ptr = xyz;
- ABC** dptr1 = &ptr; //pointer to ponter
- // or
- ABC* dptr1[] = {xyz}; //pointer to an array.
- //Thus making dptr the 'logical' equivalent of ABC[1][2]
- > if i pass dptr1 to func, and func does something like *ptr[0] and *ptr[1] to access the actual values, it fails.
- ABC value[1][2];
- ABC row1[3] = {/*STUFF 1*/};
- ABC row2[3] = {/*STUFF 2*/};
- ABC row3[3] = {/*STUFF 3*/};
- ABC* data[3] = {row1,row2,row3}; // logical ABC data[3][3];
- func(data);
- #define count(ARRAY) (sizeof(ARRAY)/sizeof(*ARRAY))
- void func(struct ABC * array, size_t elementCount) {...}
- struct ABC anArray[2] = {...};
- func(anArray, count(anArray));
- struct ABC array[2] = {...};
- struct ABC * parray[count(array)];
- for(size_t i = 0; i < count(array); ++i)
- parray[i] = &array[i];
- struct ABC * parray[count(array) + 1];
- parray[count(array)] = NULL;
- struct ABC parray[][1] = {
- { {/* first struct's initializer */} },
- { {/* second struct's initializer */} },
- { {/* third struct's initializer */} }
- };
- func(parray, count(parray));
- struct ABC
- {
- // some members;
- };
- void func( ABC* firstElemOfArray, int countOfElementsInArray)
- {
- for( int i = 0; i < countOfElementsInArray; ++i )
- {
- ABC* currentElement = firstElemOfArray + i;
- // do something with current elements
- }
- }
- void useFunc()
- {
- ABC array[2] = { new ABC(), new ABC() };
- func( array, sizeof(array/sizeof(array[0]) );
- }
- typedef ABC* ABC_ptr;
- ABC_ptr *dptr2 = new ABC_ptr[2];
Add Comment
Please, Sign In to add comment