White Space in LINK.EXE Directives

In general, directives are separated by white space in the source text. However, they may themselves contain white space due to a facility for enclosure by double-quotes. This facility works very slightly differently, but with non-trivial implications, depending on the source.

Directives on the actual command line are separated by the C Run-Time Library (specifically by the __getmainargs function in MSVCR70.DLL), according to the usual C-language rules of parsing command-line arguments for the main function. The separated arguments become the separate directives. The parsing treats the double-quote and backslash specially. Where a double-quote is preceded by an odd number of backslashes, it is a literal double-quote. What passes from the command line into the argument is one backslash for each pair, plus one double-quote. Where a double-quote is preceded by an even number of backslashes, including by no backslashes, what passes into the argument is one backslash for each pair. The double-quote is discarded except to signify that until the next non-literal double-quote (if any), white space does not act as an argument separator. This matching non-literal double-quote also does not pass into the argument.

For directives from other sources, i.e., from command files and environment variables, separation is handled by the linker’s own code which does not go to quite the same trouble. Backslashes are always just backslashes and there is no support for a literal double-quote. Any double-quote disables white space as a separator of directives until the next double-quote (if any). Neither the first double-quote nor its match passes from the source text into the directive.

Whether the difference has any effect in practice depends on what the programmer wants to do, and with what methods and tools. There follow a few quick speculations.

Occasions for wanting a double-quote inside a directive must be very few, especially since the double-quote is not a valid character in filenames or symbols. However, should such a directive be wanted, it can be given only on the actual command line, and only by knowing to use the backslash as an escape character.

The special interpretation of the backslash makes for some trouble if composing a pathname from elements that already have their white space enclosed by double-quotes. If the pathname goes into a directive on the actual command line, then a straightforward concatenation with backslashes between path elements is unreliable since a double-quote at the start of an element becomes literal and the preceding backslash disappears.