0

Isn't the answer is "A" because function overloading isn't allowed in C?

More than one function in the same file may have the same name:

A. never in C and only if their signatures are unambiguously different in C++.

B. only if they are all declared static.

C. if all but 1 are declared static or const.

D. only if no external variables are used.

Jackie Dalen
  • 49
  • 1
  • 9
  • Yes, I think the answer is A. But I don't know what does _unambiguously different signatures_ mean. – rodrigo Nov 04 '13 at 17:33
  • 5
    The answer is A, also because all the others don't make sense in any way. – Matteo Italia Nov 04 '13 at 17:34
  • @rodrigo: working backwards from the assumption that the answer is correct, it must mean for example that `void foo(int)` is unambiguously different from `void foo(long)`, whereas `void foo(int)` is not unambiguously different from `void foo(int32_t)` in all implementations because those might be the same type. But I think the word "unambiguous" is redundant: two function signatures are either different or they're not :-) – Steve Jessop Nov 04 '13 at 17:36
  • In the context of overloading, `int foo(int)` and `void foo(int)` are different but not unambiguously different, since using both will cause an ambiguous overload error. So that's probably what its trying to say. But I agree the term *unambiguously different* is itself ambiguous. – Chris Dodd Nov 04 '13 at 17:58
  • @rodrigo: I think it means the data types of the parameter(s) and/or return type(s) are different between the functions. – Jackie Dalen Nov 04 '13 at 18:21
  • @JackieDalen: Only that the return type is not used in C++ overloading. – rodrigo Nov 04 '13 at 19:14

1 Answers1

2

C doesn't support overloading.

In C++, keywords static and const* can not effect on overloading.

Then A is the answer.


* Not const for constant member functions inside a class declaration to make this pointer a const.

masoud
  • 55,379
  • 16
  • 141
  • 208
  • It is now possible to overload functions using `__Generic`. See [this answer](https://stackoverflow.com/questions/479207/how-to-achieve-function-overloading-in-c), for example. – Anderson Green May 21 '19 at 21:25