tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] How to use char "\"


From: Charles Gordon
Subject: Re: [Tinycc-devel] How to use char "\"
Date: Tue, 30 Sep 2014 23:47:39 +0200

On 30 sept. 2014, at 21:47, Evan Langlois <address@hidden> wrote:

On Tue, Sep 30, 2014 at 2:18 PM, JFC Morfin <address@hidden> wrote:
>> 
>> The question is not about bugs. These are ten years old libraries used 
>> millions of time but compiled under Borland. There are differences between 
>> compilers. The question is only to understand them.
> 
> Borland isn't known for its standards compliance.  My guess is that Borland 
> wasn't handling the escape sequences properly and ignoring unknown ones or 
> something.  The standard specifically states that its supposed to throw up a 
> warning if it finds an unknown escape.  Now you have TCC and GCC and they are 
> doing it right, and your having problems.  BTW, according to the standard, ? 
> should be escaped as well.  So \*? becomes "\\*\?”

Not exactly:  the C Standard *allows* ? to be escaped as \?, it does not 
specify that it should be.
Similarly, ‘ can be escaped as \’ in strings and “ can be escaped as \” in 
character constants,
but there is no obligation and aside from style and consistency of the source 
code, it makes no difference in the code generated.
But why did the standard folks allow ? to be escaped as \? might you wonder…
Because of another ominous standard deviance: trigraphs!
Imagine you have a date template that looks like this:  “??/??/??”
It looks pretty harmless, but with trigraph conversion, it translates as “\\??”
Modern compilers disable trigraphs by default or give warnings when the occur. 
To avoid trigraph expansion, there are 2 solutions: 
- use escape sequences as this  “\?\?/\?\?/\?\?”  (stylish but unreadable)
- break the string in 3 parts (or more):  e.g.  “??” “/??” “/??"
The good news is tcc does not support trigraphs at all, but try gcc and clang 
on this ;-)

Chqrlie.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]