extern "C" function return types

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

 



If you want to use C++ code from code compiled by a C compiler its
obvious that the return type of the externed function must be a valid
C type (no templates, classes, etc). However, another usage of
external C linkage is to allow for symbol discovery via a call to
dlsym(). In this case more often than not C++ code is calling the
externed function and will be able to understand C++ specific return
types. For example:

extern "C" {
     list<string> getString() {};
}

The above code compiles and runs fine with gcc. In other compilers,
namely msvc, the above code does not compile because the return type
is not valid C. I've read through the C++ specification and can't find
any statement regarding requirements on return types of extern C
functions. Most online documentation will say one way or the other,
usually depending on if its a Unix or MS source.

Is there an official ANSI/ISO C++ stance that I've missed?

Is it reasonable to expect that the above code will always work in gcc?

In case anyone is interested the best way to make the above code
portable is to pass pointers to any invalid C type:

extern "C" {
     list<string>* getString() {};
}

Thanks!
Brian Kohan


[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