简体   繁体   English

将指针的地址而不是指针作为 function 参数传递

[英]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.所以我试图理解传递给这个 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参考: 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.如果一个子程序想要 output 一个指针,就像在你的字符串解析中它停止的地方一样,你将一个指向该指针的指针传递给它,这样它就可以用那个 output 写你的指针。

Casting makes type checking quiet but you can ask for silly things. Casting 使类型检查变得安静,但你可以要求一些愚蠢的事情。 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. void 指针,根据定义,可以强制转换或赋值为指向任何东西,包括指针、指针指针、指针指针等。指针只是一个大态度的无符号长,它指向的类型,并且强制转换会改变它。

freeRTOS queue function passes the message. freeRTOS 队列 function 传递消息。 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 完全相同。 memcpy parameters are void * and any pointer can be passed to this function. memcpy 参数是void *并且任何指针都可以传递给这个 function。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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