Closed wxtrac closed 2 years ago
c-linkage.diff
(72.7 KiB)What specific problem does this patch solve? wxWidgets is a C++ library and requires C++ to develop. Why/how would you link to wxWidgets from C?
Yes, wxWidgets is C++, but GTK+, expat, and X are not. wxWidgets defines callback functions used by those libraries. Any function meant to be called from C which is defined in a C++ file should be declared to have C linkage, which is done by using extern "C". Same for a function pointer used to call a function in a C library. Some compilers do warn about this kind of thing. Here is an example (one of many), from Sun Forte 7.
"../src/gtk/button.cpp", line 307: Warning (Anachronism): Formal argument widget_new of type _GtkWidget()() in call to static wxControl::GetDefaultAttributesFromGTKWidget(_GtkWidget()(), bool, int) is being passed extern "C" _GtkWidget()().
I don't know whether or not Sun Forte 7 is a support compiler or not (officially supported by wxWidgets, I mean). AFAIK, gcc doesn't warn about this. OpenWatcom on Windows throws tons of extra warnings not generated by other compilers, some of which get silenced, some of which get ignored. Does anything actually not work as a result?
Anyway, thanks for clearing up exactly what the problem was. I've done my duty, the acceptance or rejection of this patch will be left for others to decide.
This issue is nothing new, see the comments in src/gtk/app.cpp, line 196, and src/common/dynarray.cpp, line 437. This patch just makes things more consistent.
Your patch was applied to CVS HEAD, thanks!
Issue migrated from trac ticket # 7154
priority: normal
2005-03-05 19:29:15: @paulcor created the issue
Any function called from C code should have C linkage. Same for a function pointer used to call a C function from C++. There is no requirement that C and C++ linkage be compatible.