简体   繁体   English

传递给C中的函数arg时结构指针与结构之间的区别

[英]Difference between structure pointer and structure when passed to function arg in C

I have following query: 我有以下查询:

THis is my structure in some .h file 这是我在.h文件中的结构

typedef struct 
    {
        recUEInfo_t  *recUEInfoPtr_t;
        Int32   frameID;
        Int32   slotIndx;
        Int32   symNumber;

    }   recControlList;

If I do recControlList recControlListPtr; 如果我这样做recControlList recControlListPtr; I can pass address to caller function and collect it as a pointer in the definition 我可以将地址传递给调用方函数,并将其收集为定义中的指针

Fun(recControlListPtr);/* caller*/

and void Fun(*recControlListPtr);/* actual func*/ void Fun(*recControlListPtr);/* actual func*/

But if i do recControlList *recControlListPtr; 但是如果我这样做recControlList *recControlListPtr; then what should I do to get the correct pointer? 那我该怎么做才能得到正确的指针?

Please help 请帮忙

I misunderstood who was the declarer and caller of the function initially, sorry about that, so if the function definition is: 我最初误解了谁是函数的声明者和调用者,对此感到抱歉,因此,如果函数定义为:

Fun(recControlListPtr *precControlListPtr)
{
    // Do stuff
}

You could call this way: 您可以这样称呼:

recControlListPtr rec1;
recContrlListPtr* prec2;
Fun(&rec1);
Fun(prec2);

Additional edit - My best guess at what I think you are trying to accomplish 其他编辑-我对您认为要完成的工作的最佳猜测

typedef struct 
{
    recUEInfo_t  *recUEInfoPtr_t;
    int   frameID;
    int   slotIndx;
    int   symNumber;

}   recControlList;

void Fun(recControlList* pRecList)
{
    ASSERT(pRecList != NULL);
    int nFrameID = pRecList->frameID; // This line shows accessing the struct
    // Do other stuff
}

recControlList  rec1;
recControlList* pRec2 = &rec1;
Fun(&rec1);
Fun(pRec2);

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

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