2

I guess something is fundamentally wrong, I would like to send this global :

static char content[MAX_NUM_WORDS][MAX_WORD_LEN];

as an argument to a function pointer , where the function pointer def :

void(*flashReadDelegate)(char*[])=0;

and calling it with :

//save some data in (which prints ok)
strcpy(content[record_desc.record_id],toSave);

// ***Send the delegate out
(*flashReadDelegate)(content);  // ** here there is a compiler warnning about the argument

So how should the pointer argument look like if I want to send content ?

2 Answers 2

5

void(*flashReadDelegate)(char*[])=0; is wrong. Your function pointer should be like this

void (*flashReadDelegate)(char (*)[MAX_WORD_LEN]);  

You have not mentioned the prototype of the function to which flashReadDelegate is pointing. I am assuming that it's prototype would be

void func(char (*)[MAX_WORD_LEN]);

Now, in the function call (*flashReadDelegate)(content);, the argument array content will be converted to a pointer to an array of MAX_WORD_LEN chars ((*)[MAX_WORD_LEN]).

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks a lot! So why is my arg wrong? Isn't it a pointer to strings?
@Curnelious; As a function parameter char*[] is equivalent to char**.
Well char*[] reduces to pointer to the 1st element of an array of characters where as char (*)[MAX_WORD_LEN] reduces to a pointer to an array of characters with each array element being MAX_WORD_LEN characters wide
1

Your declaration of content is not a pointer to strings. It is an array of MAX_NUM_WORDS strings of MAX_WORD_LEN characters.

If you want an array of strings you would need to declare content as: static char* content[MAX_NUM_WORDS];`

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.