Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: trigraphs, yecch

Reply
Thread Tools

Re: trigraphs, yecch

 
 
Patrick Scheible
Guest
Posts: n/a
 
      02-01-2012
"Charles Richmond" <> writes:

> "Patrick Scheible" <> wrote in message
> news:...
>> Keith Thompson <kst-> writes:
>>
>>> (Richard Harter) writes:
>>>> The other day I wanted to put three successive question marks in a
>>>> string. Frex, "(???).%s.%s". My trusty antique gcc compiler
>>>> converted the last two '?'s into a ']' along with a warning that it
>>>> was doing a trigraph conversion.
>>>>
>>>> Now, me, I know from nothing about trigraphs - never used them, hope
>>>> never to use them - so I was caught by surprise. My elderly copy of
>>>> K&R described them but I didn't see anything about getting around
>>>> them.
>>>>
>>>> So. How is one supposed to get three successive question marks into a
>>>> string?
>>>
>>> For reference, there are exactly 9 trigraphs. C99 5.2.1.1:
>>>
>>> All occurrences in a source file of the following sequences of three
>>> characters (called trigraph sequences) are replaced with the
>>> corresponding single character.
>>>
>>> ??= # ??) ] ??! |
>>> ??( [ ??' ^ ??> }
>>> ??/ \ ??< { ??- ~
>>>
>>> No other trigraph sequences exist. Each ? that does not begin one of
>>> the trigraphs listed above is not changed.
>>>
>>> In your case, "???" is not a trigraph, but ??) is.

>>
>> Has the C standards committee been flamed enough for trigraphs? I don't
>> think so. I bet there's 1000 programmers bitten by them for every 1
>> who's been helped. By 1989 anyone who didn't have an editor capable of
>> typing any 7-bit ASCII character was a hopeless luddite who would be
>> better served making their own pre-preprocessing phase for C and leaving
>> the language unchanged instead of another phase in the preprocessor for
>> every C program forever and ever.
>>

>
> So just *remove* trigraphs from the *next* C standard. Or require the
> preprocessor symbol "__TRIGRAPH_IMPLEMENTED__" to be defined, or
> relegate this to a PRAGMA... before trigraphs would be recognized by
> the compiler. Make it *extra* hard for the ordinary C programmer to
> step on this land mine.


Yes, this is the best thing to do now, since it's to late to have never
put them in the language in the first place.

-- Patrick
 
Reply With Quote
 
 
 
 
Stephen Sprunk
Guest
Posts: n/a
 
      02-01-2012
On 31-Jan-12 23:50, Charles Richmond wrote:
>> Keith Thompson <kst-> writes:
>>> For reference, there are exactly 9 trigraphs. C99 5.2.1.1:
>>>
>>> All occurrences in a source file of the following sequences of three
>>> characters (called trigraph sequences) are replaced with the
>>> corresponding single character.
>>>
>>> ??= # ??) ] ??! |
>>> ??( [ ??' ^ ??> }
>>> ??/ \ ??< { ??- ~

....
> So just *remove* trigraphs from the *next* C standard. Or require the
> preprocessor symbol "__TRIGRAPH_IMPLEMENTED__" to be defined,


How would that help? If someone knows to check for that symbol,
presumably they also know not to inadvertently use trigraphs.

> or relegate this to a PRAGMA... before trigraphs would be recognized
> by the compiler.


You couldn't use a #pragma to enable trigraphs since # is one of the
characters that may require a trigraph. See above.

S

--
Stephen Sprunk "God does not play dice." --Albert Einstein
CCIE #3723 "God is an inveterate gambler, and He throws the
K5SSS dice at every possible opportunity." --Stephen Hawking
 
Reply With Quote
 
 
 
 
Ben Pfaff
Guest
Posts: n/a
 
      02-01-2012
Stephen Sprunk <> writes:

> On 31-Jan-12 23:50, Charles Richmond wrote:
>> or relegate this to a PRAGMA... before trigraphs would be recognized
>> by the compiler.

>
> You couldn't use a #pragma to enable trigraphs since # is one of the
> characters that may require a trigraph. See above.


You could use a %ragma to enable trigraphs.
--
char a[]="\n .CJacehknorstu";int putchar(int);int main(void){unsigned long b[]
={0x67dffdff,0x9aa9aa6a,0xa77ffda9,0x7da6aa6a,0xa6 7f6aaa,0xaa9aa9f6,0x11f6},*p
=b,i=24;for(;p+=!*p;*p/=4)switch(0[p]&3)case 0:{return 0;for(p--;i--;i--)case+
2:{i++;if(i)break;else default:continue;if(0)case 1utchar(a[i&15]);break;}}}
 
Reply With Quote
 
Kaz Kylheku
Guest
Posts: n/a
 
      02-01-2012
On 2012-02-01, Ben Pfaff <> wrote:
> Stephen Sprunk <> writes:
>
>> On 31-Jan-12 23:50, Charles Richmond wrote:
>>> or relegate this to a PRAGMA... before trigraphs would be recognized
>>> by the compiler.

>>
>> You couldn't use a #pragma to enable trigraphs since # is one of the
>> characters that may require a trigraph. See above.

>
> You could use a %ragma to enable trigraphs.


Even better:

??=pragma


 
Reply With Quote
 
Ben Pfaff
Guest
Posts: n/a
 
      02-01-2012
Kaz Kylheku <> writes:

> On 2012-02-01, Ben Pfaff <> wrote:
>> Stephen Sprunk <> writes:
>>
>>> On 31-Jan-12 23:50, Charles Richmond wrote:
>>>> or relegate this to a PRAGMA... before trigraphs would be recognized
>>>> by the compiler.
>>>
>>> You couldn't use a #pragma to enable trigraphs since # is one of the
>>> characters that may require a trigraph. See above.

>>
>> You could use a %ragma to enable trigraphs.

>
> Even better:
>
> ??=pragma


You couldn't use ??=pragma to enable trigraphs because ??= is a
trigraph. See above.
--
char a[]="\n .CJacehknorstu";int putchar(int);int main(void){unsigned long b[]
={0x67dffdff,0x9aa9aa6a,0xa77ffda9,0x7da6aa6a,0xa6 7f6aaa,0xaa9aa9f6,0x11f6},*p
=b,i=24;for(;p+=!*p;*p/=4)switch(0[p]&3)case 0:{return 0;for(p--;i--;i--)case+
2:{i++;if(i)break;else default:continue;if(0)case 1utchar(a[i&15]);break;}}}
 
Reply With Quote
 
Stephen Sprunk
Guest
Posts: n/a
 
      02-01-2012
On 01-Feb-12 13:35, Ben Pfaff wrote:
> Stephen Sprunk <> writes:
>
>> On 31-Jan-12 23:50, Charles Richmond wrote:
>>> or relegate this to a PRAGMA... before trigraphs would be recognized
>>> by the compiler.

>>
>> You couldn't use a #pragma to enable trigraphs since # is one of the
>> characters that may require a trigraph. See above.

>
> You could use a %ragma to enable trigraphs.


Or, to avoid creating yet another bizarre sequence of symbols, you could
create a special exception for "??=pragma trigraph", without recognizing
any other trigraphs by default.

However, that still seems like a hack; it seems more straightforward to
allow implementations to optionally ignore trigraphs via some external
means, which is the status quo anyway.

S


--
Stephen Sprunk "God does not play dice." --Albert Einstein
CCIE #3723 "God is an inveterate gambler, and He throws the
K5SSS dice at every possible opportunity." --Stephen Hawking
 
Reply With Quote
 
Kaz Kylheku
Guest
Posts: n/a
 
      02-01-2012
On 2012-02-01, Stephen Sprunk <> wrote:
> On 01-Feb-12 13:35, Ben Pfaff wrote:
>> Stephen Sprunk <> writes:
>>
>>> On 31-Jan-12 23:50, Charles Richmond wrote:
>>>> or relegate this to a PRAGMA... before trigraphs would be recognized
>>>> by the compiler.
>>>
>>> You couldn't use a #pragma to enable trigraphs since # is one of the
>>> characters that may require a trigraph. See above.

>>
>> You could use a %ragma to enable trigraphs.

>
> Or, to avoid creating yet another bizarre sequence of symbols, you could
> create a special exception for "??=pragma trigraph", without recognizing
> any other trigraphs by default.


No special exception! ??=pragma trigraph enables trigraphs, but ??= is not
recognized until trigraphs are enabled.

That is the perfect solution.
 
Reply With Quote
 
Kaz Kylheku
Guest
Posts: n/a
 
      02-01-2012
On 2012-02-01, Ben Pfaff <> wrote:
> Kaz Kylheku <> writes:
>
>> On 2012-02-01, Ben Pfaff <> wrote:
>>> Stephen Sprunk <> writes:
>>>
>>>> On 31-Jan-12 23:50, Charles Richmond wrote:
>>>>> or relegate this to a PRAGMA... before trigraphs would be recognized
>>>>> by the compiler.
>>>>
>>>> You couldn't use a #pragma to enable trigraphs since # is one of the
>>>> characters that may require a trigraph. See above.
>>>
>>> You could use a %ragma to enable trigraphs.

>>
>> Even better:
>>
>> ??=pragma

>
> You couldn't use ??=pragma to enable trigraphs because ??= is a
> trigraph. See above.


So you understand the point perfectly!
 
Reply With Quote
 
Joe keane
Guest
Posts: n/a
 
      02-02-2012
In article <>,
Patrick Scheible <> wrote:
>Has the C standards committee been flamed enough for trigraphs?


I don't think so.

http://upload.wikimedia.org/wikipedi...an-picture.jpg

http://www.youtube.com/watch?v=NUHy3IgqlHc
 
Reply With Quote
 
Patrick Scheible
Guest
Posts: n/a
 
      02-07-2012
"christian.bau" <> writes:

> On Feb 1, 5:50Â*am, "Charles Richmond" <netn...@aquaporin4.com> wrote:
>
>> So just *remove* trigraphs from the *next* C standard. Â*Or require the
>> preprocessor symbol "__TRIGRAPH_IMPLEMENTED__" to be defined, or relegate
>> this to a PRAGMA... Â*before trigraphs would be recognized by the compiler.
>> Make it *extra* hard for the ordinary C programmer to step on this land
>> mine.

>
> A change that would silently break existing code.


How much existing code uses trigraphs?

-- Patrick
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: trigraphs, yecch Ben Bacarisse C Programming 9 02-01-2012 01:27 PM
Re: trigraphs, yecch Peter Nilsson C Programming 7 02-01-2012 12:15 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57