Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a C function have multiple signatures? [duplicate]

Tags:

Possible Duplicate:
function overloading in C

Apologies if this is a dup but if it is, I can't find it.

In C, can you define multiple functions with the same function name, but with different parameters? I come from a C# background. In C#, the following code is completely legal.

//Our first function

int MyFunction() {     //Code here     return i; }  int MyFunction(int passAParameter) {     // Code using passAParameter     return i; } 

In my specific case, I would like to create a function that has one optional parameter (that is an int) at the end of the parameter list. Can this be done?

like image 583
RLH Avatar asked Sep 30 '11 18:09

RLH


People also ask

What is a function signature C?

Function Signature A function's signature includes the function's name and the number, order and type of its formal parameters. Two overloaded functions must not have the same signature. The return value is not part of a function's signature.

Does C have function overloading?

Function overloading is a feature of Object Oriented programming languages like Java and C++. As we know, C is not an Object Oriented programming language. Therefore, C does not support function overloading. However, we do have an alternative if at all we want to implement function overloading in C.

What is function overloading?

An overloaded function is really just a set of different functions that happen to have the same name. The determination of which function to use for a particular call is resolved at compile time. In Java, function overloading is also known as compile-time polymorphism and static polymorphism.


2 Answers

No. C does not support overloading.

like image 154
James McNellis Avatar answered Oct 02 '22 17:10

James McNellis


No. In strict C, you cannot do overloading.

However, given that most C compilers also support C++, and C++ does support overloading, there's a good chance you can do overloading if you're using a mainstream C/C++ compiler.

But its not strictly standard or portable to pure-C environments.

like image 44
abelenky Avatar answered Oct 02 '22 15:10

abelenky