Xref: utzoo comp.lang.c++:5980 gnu.g++.bug:1264 Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!usc!samsung!uunet!portal!cup.portal.com!pkturner From: pkturner@cup.portal.com (Prescott K Turner) Newsgroups: comp.lang.c++,gnu.g++.bug Subject: Re: Linkage & a question on name mangling Message-ID: <25400@cup.portal.com> Date: 27 Dec 89 02:27:47 GMT References: <1545@aber-cs.UUCP> <259312BD.11972@paris.ics.uci.edu> Distribution: usa Organization: The Portal System (TM) Lines: 37 In article <259312BD.11972@paris.ics.uci.edu> rfg@ics.uci.edu (Ron Guilmette) w rites: > In article <1545@aber-cs.UUCP> pcg@cs.aber.ac.uk (Piercarlo Grandi) writes: > > ... > >Notice that since mangling does not apply to variable names yet... > > Yes. Can somebody please tell me why that is the case? It seems to me that > all of the "type checking" effects that are squeezed out of the linker via > name mangling function names would be equally applicable to the problem > of assuring that the types of variables and (extern) const's were consistant > across object files. What's the story? This was a conscious decision documented in Stroustrup's paper on type-safe linkage at Usenix '88. The difference between variables and functions is that in most references to a function name, arguments are present which neatly determine which overloaded alternative to call. Consider a header file which declares extern long count; then in a file which includes this header a user declares int count; ... // and refer to count: long i = count; There are two ways to look at this that relate to name mangling: 1. "count" is an overloaded variable name, and the user is going to get the variable declared long. 2. "count" has inconsistent declarations. Number 1 is unsatisfactory because this kind of example can surprise the user. The paper doesn't find it worth discussing. Number 2 is not supported by name mangling. Since "long count" and "int count" would have different mangled names, the linker would not find the error in the program. -- Prescott K. Turner, Jr. Language Processors, Inc. 959 Concord St., Framingham, MA 01701 USA (508) 626-0006 x232 UUCP: ...sun!cup.portal.com!pkturner Internet: pkturner@cup.portal.com