简体   繁体   中英

Passing an address of a pointer instead of a pointer as a function argument

So I'm trying to understand the argument passing to this function.

The second argument takes a pointer

BaseType_t xQueueGenericSend( QueueHandle_t xQueue, const void * const pvItemToQueue, TickType_t xTicksToWait, const BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION;

then how come passing an address of a pointer is legit?

struct AMessage *pxMessage;
pxMessage = & xMessage;
xQueueGenericSend( xQueue2, ( void * ) &pxMessage, ( portTickType ) 0, queueSEND_TO_BACK );
 

Reference: http://web.ist.utl.pt/~ist11993/FRTOS-API/group___queue_management.html#xQueueGenericSend

If a subroutine wants to output a pointer, like where in the parse of your string it stopped, you pass it a pointer to that pointer, so it can write your pointer with that output.

Casting makes type checking quiet but you can ask for silly things. A void pointer, by definition, can be cast or assigned to point to anything, including a pointer, a pointer to a pointer, a pointer to a pointer to a pointer, etc. A pointer is just an unsigned long with a big attitude, the type it points to, and a cast changes that.

freeRTOS queue function passes the message. If the message is the pointer you need to pas reference to it. Then this reference is being dereferenced.

In this case the pointer to message is going to be queued - not the message itself.

It works exactly as memcpy. memcpy parameters are void * and any pointer can be passed to this function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM