Reputation: 1939
I have a 2D array like this and I want a pointer to it.
Currently I have this:
char* recv_args_msg_queue[20];
char** ref_temp = &recv_args_msg_queue[0];
char*** ref_queue = &ref_temp;
But I feel my way is really dumb. Is there a way to do it on one line?
Note:
char* recv_args_msg_queue[20];
is later in my code allocated properly to be an array. I just wanted dynamic allocation otherwise I could have wrote:
char recv_args_msg_queue[20][another_number_here];
Upvotes: 1
Views: 117
Reputation: 20336
Using a typedef for your array type will make easier getting a pointer to it.
Your code would look like this:
typedef char* msg_queue20[20];
msg_queue20 recv_args_msg_queue;
msg_queue20* ref_queue = &recv_args_msg_queue;
Take care of reading the link I posted, as it contains important recommendations.
Upvotes: 3