On Tue, 6 Jul 2004, Bernhard Holzmayer wrote:[color=blue]
>
> Francesco Zavatarelli wrote:[color=green]
> >
> > char* NAME_SMS = "c:\\Program Files\\Palm\\Tungst\\Backup\\SmsDB.PDB";[/color][/color]
[...][color=blue]
> The reason why it fails, is obviously bc. of how escape sequences
> are handled.[/color]
Aha! Someone who uses "obviously" even more inappropriately than
myself! ;-) s/bc. of/not because of/
[color=blue]
> \\ evaluates to \ in the first stage of the lexical parsing,[/color]
Terminology is important in this newsgroup. \\ isn't an expression
and doesn't "evaluate" to anything. Nor does the first phase of
translation do anything special with backslashes. You might say
that "Doubled backslashes inside strings 'turn into' single backslashes
in the compiled program," with more elaboration depending on context
and relevancy.
[color=blue]
> then the sequence is searched for things like %s in a printf ...
> This time it assumes that the backslash indicates that the following
> token is meant as some special character / escape sequence.[/color]
Wrong, of course. You may be confusing C strings with Perl
quoting operators, which do all kinds of weird stuff. There's nothing
magic about the percent sign in C, and the only magic thing about
backslashes is the way doubled ones turn into single ones, only
once, during translation phase 5.
[color=blue]
> If the resulting string should really contain backslashes as folder
> separators, it might help to do an additional masking like
> char* NAME_SMS = "c:\\\\Program...
> That's not a joke.[/color]
Then it's misguided, because taken literally it's very, very wrong.
[color=blue]
> In a certain chain of cascaded parsing stages in a real project,
> I had to insert 8 backslashes in every place where you'd expect one
> in the final output. So, don't wonder - take it easy - if it works.[/color]
This I find hard to believe. Do you still have the code anywhere,
or can you reconstruct it accurately from memory? I *have* had
occasion to use an octuple-backslash (line 61 of
http://www.contrib.andrew.cmu.edu/~a...ftware/quine.c
) but that was in a toy program done purely for hack value, not
for any practical purpose.
[color=blue]
> Another possibility:
> Some compilers understand forward slashes and will interpret them
> correctly, so you'd try
> char* NAME_SMS = "c:/Program.../SmsDB.PDB";[/color]
This is not a compiler issue (all C compilers understand forward
slashes, since otherwise how could you divide two numbers?) but
rather an operating-system issue (most OSes understand slashes at
the system level, with some obvious exceptions and some not-so-
obvious non-exceptions, such as MS-DOS and Win32).
[color=blue]
> Then, to indicate the drive letter, try this one (used @ cygnus gcc)
> char* NAME_SMS = "//c/Program...[/color]
This is a Unix convention and is highly unlikely to work on the
OP's Windows OS.
[color=blue]
> The blank will certainly add additional problems as the other
> posters indicated.
> One chance is to merely escape it by one or two backslashes,
> char* NAME_SMS = "//c/Program\ Files/... or
> char* NAME_SMS = "//c/Program\\ Files/...[/color]
One backslash ==> compiler diagnostic.
Two backslashes ==> might work, but I doubt it. (Untested.)
-Arthur