wxWidgets / wxWidgets

Cross-Platform C++ GUI Library
https://www.wxwidgets.org/
6.05k stars 1.76k forks source link

C callbacks should have C linkage #7154

Closed wxtrac closed 2 years ago

wxtrac commented 19 years ago

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.

wxtrac commented 19 years ago

2005-03-05 19:29:16: @paulcor uploaded file c-linkage.diff (72.7 KiB)

wxtrac commented 19 years ago

2005-03-06 04:24:15: hockkn (Kevin Hock) commented


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?

wxtrac commented 19 years ago

2005-03-06 07:11:27: @paulcor commented


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()().

wxtrac commented 19 years ago

2005-03-06 07:23:06: hockkn (Kevin Hock) commented


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.

wxtrac commented 19 years ago

2005-03-07 07:36:19: @paulcor commented


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.

wxtrac commented 19 years ago

2005-03-22 00:46:29: @vadz commented


Your patch was applied to CVS HEAD, thanks!