What is forward reference in C?

后端 未结 6 1858

What is forward reference in C with respect to pointers?

Can I get an example?

6条回答
  •  星月不相逢
    2020-12-14 13:44

    See this page on forward references. I don't see how forward referencing would be different with pointers and with other PoD types.

    Note that you can forward declare types, and declare variables which are pointers to that type:

    struct MyStruct;
    struct MyStruct *ptr;
    struct MyStruct var;  // ILLEGAL
    ptr->member;  // ILLEGAL
    
    struct MyStruct {
        // ...
    };
    
    // Or:
    
    typedef struct MyStruct MyStruct;
    MyStruct *ptr;
    MyStruct var;  // ILLEGAL
    ptr->member;  // ILLEGAL
    
    struct MyStruct {
        // ...
    };
    

    I think this is what you're asking for when dealing with pointers and forward declaration.

提交回复
热议问题