Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!uunet!jarthur!elroy.jpl.nasa.gov!cit-vax!ronen From: ronen@cit-vax.Caltech.Edu (Ronen Barzel) Newsgroups: comp.lang.c++ Subject: internal linkage for member functions? Message-ID: <14373@cit-vax.Caltech.Edu> Date: 22 Mar 90 02:07:59 GMT Organization: California Institute of Technology Lines: 61 C++ does not seem to allow "internal linkage" for member functions. Am I wrong -- is there a way to do it? (If there isn't, IMHO there should be.) Lippman sec 3.9 "static Global Variable" says: "A global identifier preceded by the keyword 'static' will be invisible outside the file in which it is defined... Static identifiers at file scope are spoken of has having _internal_linkage_." Preceding a declaration of a member function with 'static' isn't covered by this. If I try it, cfront gives an error "static specified for qualified name foo()" -Ronen [To answer the obvious question "why would you ever want to do that?", I'll describe the scenario in which I want it: I am writing a file to be included in a library; the file defines some user-callable functions. Within that file, I declare a class with member functions; the class is only used internally by the library routines -- the user knows nothing about it. Unfortunately, the mangled member function names get entered into the .o as global symbols. // foo.H -- header file for "foo" library extern void public_foo(); // foo.C -- implements "foo" library #include "foo.H" class internal { public: func(); } internal::func() // want this to be 'static' { // ... } void public_foo() { internal x; x.func(); // ... } The symbol table for foo.o includes two global text symbols: "public_foo__Fv" (the one I want) and "func__8internalFv" (the one I want to get rid of). I have two problems with this: 1. I can't use the same class & member names in more than one file in the library. (A different file might want to define a different 'internal' class with member function 'func'.) 2. The extra symbols clutter up the .o file; aside from being aestheticaly unappealing, on a large scale it will lead to slower link times, etc. (Yes, the unwanted symbol can be removed via "ld -r -h func__8internalFv" or whatever is analogous on your platform, but that's sort of ugly.) ]