开发者

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

开发者_高级运维typedef struct 
    {
        recUEInfo_t  *recUEInfoPtr_t;
        Int32   frameID;
        Int32   slotIndx;
        Int32   symNumber;

    }   recControlList;

If I do 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*/

But if i do 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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜