Re: Warning for incompatible functions declared 'extern "C"'?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 23 July 2014 23:53, Nick wrote:
> I have an oversight in my code where I'm declaring & defining a function
> with C-linkage, though it's not possible.
>
> Example snippet:
>
> <snip>
> //------------------------------------------------------------
>
> #ifdef __cplusplus
> extern "C"
> {
> #endif
>
> // ... some functions which are compatible with C linkage
>
> // Intended to be a helper function not exposed from library
> std::string GetEngineVersion()
> {
>     // ...
> }
>
> #ifdef __cplusplus
> }
> #endif
>
> //------------------------------------------------------------
> </snip>
>
>
> Obviously the GetEngineVersion function cannot have C linkage because it
> returns a C++ class.

That is valid C++ code. C linkage doesn't mean the function has to
actually be usable from C.

You can also declare functions with C linkage that take reference
parameters or throw exceptions.

> My question is:  does GCC have a warning for this scenario?
> Specifically, can it warn when something is declared extern "C" that's
> incompatible with C linkage?

No, there is no such warning as far as I know.

Such a warning doesn't seem unreasonable, since *usually* (not not
always) you want functions with C language linkage to be callable from
C.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux