C LanguageFunction Overloading is not supported. If two identical functions are defined, an error is returned.
Eg:
// Test. c
# Include <stdio. h>
# Include <stdlib. h>
Int add (int A, int B)
{
Return A + B;
}
Int add (int A, int B, int C)
{
Return A + B + C;
}
Int main (INT argc, char * argv [])
{
If (argc! = 3 & argc! = 4)
{
Printf ("usage ./ProgramName: int Int or./program name: int/N ");
Exit (1 );
}
If (argc = 3 ){
Printf ("% S + % s = % d/N", argv [1], argv [2], add (atoi (argv [1]), atoi (argv [2]);
} Else {
Printf ("% S + % s = % d/N", argv [1], argv [2], argv [3], add (atoi (argv [1]), atoi (argv [2]), atoi (argv [3]);
}
Return 0;
}
Compilation, error:
Test. C: 9: Error: conflict with the 'add' type
Test. C: 5: Error: 'add' is defined in this
Test. C: In the 'main' function:
Test. C: 23: Error: Too few arguments are provided to the 'add' function.
After the name is changed, it runs normally:
Alei @ Alei-desktop :~ $ GCC test. C-o Test
Alei @ Alei-desktop :~ $./Test
Usage./program name int Int or./program name int
Alei @ Alei-desktop :~ $./Test 12 13
12 + 13 = 25
Alei @ Alei-desktop :~ $./Test 12 13 14
12 + 13 + 14 = 39