Re: Unrecognized escape sequences in string literals



On Tue, 11 Aug 2009 13:20:52 -0700, Douglas Alan wrote:

On Aug 11, 2:00 pm, Steven D'Aprano <st...@REMOVE-THIS-
cybersource.com.au> wrote:

test.cpp:1:1: warning: unknown escape sequence '\y'

Isn't that a warning, not a fatal error? So what does temp contain?

My "Annotated C++ Reference Manual" is packed, and surprisingly in
Stroustrup's Third Edition, there is no mention of the issue in the
entire 1,000 pages. But Microsoft to the rescue:

If you want a backslash character to appear within a string, you
must type two backslashes (\\)

(From http://msdn.microsoft.com/en-us/library/69ze775t.aspx)

Should I assume that Microsoft's C++ compiler treats it as an error, not
a warning? Or is is this *still* undefined behaviour, and MS C++ compiler
will happily compile "ab\cd" whatever it feels like?


The question of what any specific C++ does if you ignore the warning is
irrelevant, as such behavior in C++ is almost *always* undefined. Hence
the warning.

So a C++ compiler which follows Python's behaviour would be behaving
within the language specifications.

I note that the bash shell, which claims to follow C semantics, also does
what Python does:

$ echo $'a s\trin\g with escapes'
a s rin\g with escapes


Explain to me again why we're treating underspecified C++ semantics,
which may or may not do *exactly* what Python does, as if it were the One
True Way of treating escape sequences?


--
Steven
.



Relevant Pages

  • Re: STORAGE_ERROR in adainit
    ... >>It's probably a bug in your compiler that it doesn't detect the name ... So the difference is that you get a warning but an executable is ... It may well be another fatal error. ...
    (comp.lang.ada)
  • Re: Why INFINITE loop in a thread occupy so much CPU time??
    ... With the attendant warning about the constant expression. ... This is a common programming technique. ... Good programming practice would consist of using the compiler at ... One can write 'bool' in C++ but not C. ...
    (microsoft.public.vc.mfc)
  • Re: help needed please!
    ... But some compilers like to give you a warning ... Each warning a compiler can give you is important when you not ... but you may use flages to handle flags to handle flags when you ... >> stdout is line bufferd and until one or both of the following cases is ...
    (comp.lang.c)
  • Re: Overloading abstract methods
    ... I'm calling this abstract class ResumeWriter. ... > use of in each subclass is up to you. ... >> However, if I do that, I get compiler warnings that the parameters for ... Disable that warning. ...
    (comp.lang.java.programmer)
  • Re: Why does this work?
    ... The compiler is able to tell the difference between the two by the context in which the word "color" is used. ... The point is that the compiler reads the original code as attempting to access a shared member of an instance. ... That's why the compiler is warning the programmer that it's not going to do what was coded. ...
    (microsoft.public.dotnet.languages.vb)