[Bug c++/13905] New: Use of __attribute__ ((visibility("X"))) in class and struct declarations
s_gccbugzilla at nedprod dot com
gcc-bugzilla@gcc.gnu.org
Wed Jan 28 22:50:00 GMT 2004
I would like to propose G++ be extended so that you can set all members within a
class or struct at once with a single __attribute__ specifier eg;
class __attribute__ ((visibility("public"))) PublicClass {
int foo; // made public
public:
static void foo2(); // also made public
};
This not uncoincidentally is identical to MSVC's __declspec(dllexport) syntax
for classes and structs. All the macros currently used in cross-platform code
can simply use __attribute__ ((visibility("public"))) for the APIEXPORT
definition, mark the default as symbol hidden and we're done.
Typical arguments against this:
1. This exports too much stuff
On Windows developers for years have been designing the classes defined in
public to not export extraneous members, using opaque types to hide
implementation details. Therefore this is a null argument.
Besides you can always set specific members individually, thus overriding the
class setting.
2. Just because MSVC does it this way why should GCC?
Because like it or not, MSVC is a major compiler. Lots of code has been written
to use its method of exporting symbols (indeed, any Unix library which compiles
on Windows). Currently setting them per member data and per member function
requires editing too much code (plus looks VERY ugly) and I've not seen a single
project which has bothered. This has caused much namespace pollution, exposure
of far too much implementation detail and slows loading of apps generated by GCC
greatly.
3. Specifying a file with symbols to be exported to the linker is good enough.
If that were true, why do Windows applications invariably use the __declspec()
mechanism? To maintain such a file costs time, it's easy to forget or remove
symbols with changes and it's a pain in the ass. It's far easier, more
maintainable and generally nicer to extend the language to support this. Since
we already agree on this (why else is there __attribute__?), this little
alteration could make binaries generated by GCC so much nicer.
Cheers,
Niall
--
Summary: Use of __attribute__ ((visibility("X"))) in class and
struct declarations
Product: gcc
Version: 3.4.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: s_gccbugzilla at nedprod dot com
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13905
More information about the Gcc-bugs
mailing list