Reputation: 5771
I have read
However, one question that I have not found an answer to: are there (potentially, future) disadvantages to using extern "C"
(e.g., on as many functions as possible)?
To be more specific: Is there any disadvantage in adding extern "C"
to functions whose interface only use C functionality; in other words, those that do not use the features listed in @k-five's answer?
Upvotes: 4
Views: 1163
Reputation: 31447
The disadvantage is that you can only use features in the interface to extern "C"
functions that are also available to C functions.
That means:
1. you can't use default values for function arguments,
2. you can't use reference arguments,
3. you can't pass C++ classes by value (including smart pointers),
4. you can't pass enum class
arguments,
5. you can't pass bool
without converting it to int
,
6. you can't overload such functions, and probably more that I can't recall at the moment.
Upvotes: 6