algo
algo

Reputation: 151

Two functions share same signature in C

I read that C doesn't suppose function overloading. But in this Slide we can see it's not correct and my professor said: "How Is it possible that we have 2 different signatures for same function name in C?"

enter image description here

Can someone explain this?

Upvotes: 3

Views: 333

Answers (1)

Lundin
Lundin

Reputation: 214275

It isn't possible. Code such as this:

int open(const char* path, int flags);
int open(const char* path, int flags, mode_t mode);

is invalid C and will not compile (but valid C++).

However, C supports variadic functions and the old open function is implemented using that. It's actually declared as:

int open(const char *path, int oflag, ... );

Where the ... allows a variable amount of arguments through the features of stdarg.h.

Upvotes: 6

Related Questions