Home > Software engineering >  Two functions share same signature in C
Two functions share same signature in C

Time:10-12

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?

CodePudding user response:

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.

  • Related