user10607
user10607

Reputation: 3071

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.

Upvotes: 2

Views: 354

Answers (1)

unwind
unwind

Reputation: 400019

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.

Upvotes: 3

Related Questions