简体   繁体   中英

Declaring a typedef for a function returning a struct pointer?

This is an extract from a header I found in a 3rd party library:

struct aiFileIO;
struct aiFile;

// aiFile write callback
typedef size_t   (*aiFileWrite) (struct aiFile*, const char*);

// aiFileIO open callback
typedef aiFile* (*aiFileOpen)  (struct aiFileIO*, const char*);

Why does the last line not contain struct type specifier before the return type? In other words why is this last line not:

typedef struct aiFile* (*aiFileOpen)  (struct aiFileIO*, const char*);

Which would make it clear that the function returns a pointer to a struct aiFile.

In case its important the struct aiFile is defined in the same header a couple of lines later.

The only explanation I can think of is that the header was meant for C++, where you don't need to typedef struct names .

If the header is designed to be used from C, then that's a bug since the code won't build as C.

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