On 22/01/2022 12:30, Richard Damon wrote:
> On 1/22/22 3:39 AM, Alf P. Steinbach wrote:
>> On 22 Jan 2022 05:32, Joseph Hesse wrote:
>>> Hello,
>>>
>>> Suppose we compile two source files to object files with:
>>> g++ -c -std=c++14 file1.cpp file2.cpp
>>>
>>> Now we link them to an executable.
>>> g++ -o prog -std=c++14 file1.o file2.o
>>>
>>> Since the above is a linker command, do we need the -std=c++14?
>>
>> No.
>>
>> At one time, probably in the 1990's? or so but I don't know, linking
>> changed from considering only 8 significant characters in a name, to
>> supporting effectively arbitrarily long names.
>>
>> The standardized versions of the language have never had a restriction
>> to 8 significant characters, but the names in the iostreams stuff and
>> in the C library are typical of the kind of names programmers invented
>> to support that restriction.
>>
>> Another area where linking could conceivably have had different
>> requirements for different versions of the language, is the use of
>> weak symbols for `inline` things. C++17 appeared to add the
>> possibility of `inline` variables. However, the wording for templates
>> have had that as a requirement that linkers had to be able to deal
>> with, since C++98.
"weak" symbols are a different concept from inline and other merged
symbols (such as templates). Weak symbols are supported by elf format
object files, but not (IIRC) coff format. They are nothing to do with
C++, but can be used from any language.
Early C++ implementations used additional programs (typically called as
needed by driver programs such as "g++") to identify template usage and
ensure that only one copy of each shared function or object was made and
included in the linking.
For a long time, however, this has been done by smarter linkers.
>>
>> The only linker requirements change I know of for the standardized
>> language is for C++20 modules, and presumably there it's not the good
>> old common linker that deals with it (disclaimer: no experience).
>>
>>
>> - Alf
>
> The early versions of the standard, while not limiting identifier
> length, does limit the 'significant' length for external identifiers,
> allowing the implementation to truncate the name of the symbol in the
> output to the linker.
>
> In C99, 6.4.2.1p5 makes that length Implementation Defined. I would have
> to search to see if somewhere there is a guarantee of a minimum value
> for this length
In the specific case of gcc, since that is what the OP is asking about,
this kind of thing has always been "limited only by host computer
memory". In C18, implementations must support external identifiers of
at least 31 "significant initial characters". In C++14, "all characters
are significant". (I'm referring to these two, as I happen to have them
open on my desktop at the moment - not because I think they are
different relative to other versions.)
I remember vaguely that some old linkers had limits to the significant
characters in identifiers, but that was a /long/ time ago. And they
cannot have been used for C++ - name mangling for overloading functions
means that you are going to hit an 8 character limit /very/ quickly.