简体   繁体   中英

Difference of the following snippets

Please tell me what is the difference of

typedef struct Tcl_ObjType {
    char *name;
    Tcl_FreeInternalRepProc *freeIntRepProc;
    Tcl_DupInternalRepProc *dupIntRepProc;
    Tcl_UpdateStringProc *updateStringProc;
    Tcl_SetFromAnyProc *setFromAnyProc;
} Tcl_ObjType;

and

struct Tcl_ObjType {
    char *name;
    Tcl_FreeInternalRepProc *freeIntRepProc;
    Tcl_DupInternalRepProc *dupIntRepProc;
    Tcl_UpdateStringProc *updateStringProc;
    Tcl_SetFromAnyProc *setFromAnyProc;
};

I have see the first version here: http://www.tcl.tk/man/tcl8.5/TclLib/ObjectType.htm , and don't know why it is written as it is.

For C++ , there is no difference.

If this was a C program and you used the first variant, you could do:

Tcl_ObjType instanceOfStructure;

instead of

struct Tcl_ObjType instanceOfStructure;

You've gave the structure a type definition (In layman terms, provided an alternate name to an existing type):

Using your first example, you can then use it to reference objects/declare new objects via:

Tcl_ObjType newObj;

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