IT박스

C ++에서 Trigraph 시퀀스의 목적은 무엇입니까?

itboxs 2020. 7. 17. 21:11
반응형

C ++에서 Trigraph 시퀀스의 목적은 무엇입니까?


C ++ '03 Standard 2.3 / 1에 따르면 :

다른 처리가 수행되기 전에 다음 세 문자 중 하나 ( "trigraph sequence") 중 하나가 표 1에 표시된 단일 문자로 바뀝니다.

----------------------------------------------------------------------------
| trigraph | replacement | trigraph | replacement | trigraph | replacement |
----------------------------------------------------------------------------
| ??=      | #           | ??(      | [           | ??<      | {           |
| ??/      | \           | ??)      | ]           | ??>      | }           |
| ??’      | ˆ           | ??!      | |           | ??-      | ˜           |
----------------------------------------------------------------------------

실제로 문자 로 대체되는 삼중 시퀀스 이므로 코드 printf( "What??!\n" );가 인쇄 됩니다.What|??!|

내 질문은 trigraphs를 사용하는 목적은 무엇입니까? trigraphs를 사용하면 실질적인 이점이 있습니까?

UPD : 대답에 따르면 일부 유럽 키보드에는 문장 부호 문자가 모두 없으므로 미국 이외의 프로그래머는 일상 생활에서 3 점을 사용해야합니까?

UPD2 : Visual Studio 2010에는 기본적으로 3 가지 그래프 지원이 해제되어 있습니다.


밀접한 관련이있는이 질문에 대한이 질문에 대한 답이 있습니다.

ISO 646 문자 세트에 C 구문의 모든 문자가 포함되어 있지 않기 때문에 키보드와 디스플레이가있는 문자가있는 문자가있는 시스템이 있습니다. 요즘).

일반적으로 사용하지 않아도되지만 발생한 문제에 대해 정확히 알고 있어야합니다. ' ?'문자에 이스케이프 시퀀스 가있는 이유는 3 점입니다 .

'\?'

따라서 예제 문제를 피할 수있는 몇 가지 방법은 다음과 같습니다.

 printf( "What?\?!\n" ); 

 printf( "What?" "?!\n" ); 

그러나 두 개의 '?'를 입력 할 때 기억해야합니다. 당신이 3 그래프를 시작할지도 모르는 캐릭터 (그리고 내가 생각한 것은 결코 아닙니다).

실제로, 삼단 법 (trigraph)과 이력 (digraph)은 매일 전혀 걱정하지 않는 것입니다. 그러나 몇 년에 한 번 당신은 그들과 관련된 버그에 빠질 것입니다 (그리고 당신은 그들의 존재를 저주하는 데 나머지 하루를 보낼 것입니다). trigraph 또는 digraph를 발견 할 때 컴파일러가 경고 (또는 오류)하도록 구성 할 수 있다면 좋을 것이므로 의도적으로 처리해야 할 것이 있음을 알 수 있습니다.

그리고 완전성을 위해, digraph는 토큰으로 처리되기 때문에 훨씬 덜 위험하므로 문자열 리터럴 내부의 digraph는 digraph로 해석되지 않습니다.

C / C ++ 프로그램에서 구두점을 사용하여 다양한 재미에 대한 훌륭한 교육을 받으려면 (나의 머리카락을 확실히 뽑아내는 3 가지 버그 포함) Herb Sutter의 GOTW # 86 기사를 살펴보십시오 .


추가:

GCC는 기본적으로 3 점을 처리하지 않으며 경고합니다. 일부 다른 컴파일러에는 3 가지 그래프 지원을 끄는 옵션이 있습니다 (예 : IBM). Microsoft는 VS2008에서 명시 적으로 활성화해야하는 경고 (C4837)를 지원하기 시작했습니다 (-Wall 등을 사용하여).


에서 The C++ Programming Language스페셜 에디션, 페이지 829

아스키 특수 문자는 [, ], {, }, |, 및 \ISO에 의해 알파벳으로 지정된 문자 집합 위치를 차지한다. 대부분의 유럽 국가 ISO-646 문자 세트에서 이러한 위치는 영어 알파벳에서 찾을 수없는 문자로 채워집니다.

진정한 표준 최소 문자 집합을 사용하여 자국 문자를 이식 가능한 방식으로 표현할 수 있도록 일련의 삼분법이 제공됩니다. 프로그램 교환에 유용 할 수 있지만 사람들이 프로그램을 쉽게 읽을 수는 없습니다. 당연히이 문제에 대한 장기적인 해결책은 C ++ 프로그래머가 모국어와 C ++를 모두 잘 지원하는 장비를 얻는 것입니다. 불행히도, 이것은 일부에게는 불가능한 것으로 보이며, 새로운 장비의 도입은 매우 느리게 진행될 수 있습니다.


오늘 아이들! :-)

예, IBM 3270 터미널과 같은 외부 장비. 내가 기억한다면 3270에는 중괄호가 없습니다! IBM mini / 메인 프레임에 C를 쓰 려면 모든 블록 경계에 비틀린 삼중 그래프 사용해야했습니다. 다행히도 일부 IBM 미니 컴퓨터 기능 에뮬레이트 하기 위해 C로만 소프트웨어를 작성해야했지만 실제로 System / 36 에서 C 소프트웨어 작성하지는 않았습니다 .

"P"키 옆을보십시오 :

건반

흠. 말하기 어렵다. "캐리지 리턴"옆에 추가 버튼이 있으며 뒤로 가져갈 수도 있습니다. "["/ "]"쌍이 누락되었을 수 있습니다. 어쨌든이 키보드는 C를 써야한다면 슬픔을 일으킬 것입니다.

Also, these terminals display EBCDIC, IBM's "native" mainframe character set, not ASCII (thanks, Pavel Minaev, for the reminder).

On the other hand, like the GNU C guide says: "You don't need this brain damage." The gcc compiler leaves this "feature" disabled by default.


They are for use on systems that lack some of the characters in C++'s basic character set. Needless to say, such systems are exceedingly rare.


Trigraphs have been proposed for removal in C++0x. That said, there still seems to be strong argument in support of them - see C++ committee paper N2910 which discusses this. Apparently, EBCDIC is one major stronghold where they are needed.


I've seen trigraphs used in the early '90s to help convert PL/1 programs from a mainframe to be run/compiled/debugged on a PC.

They were dabbling with editing PL/I on the PC using a PL/I to C compiler and they wanted the code to work when moved back to the mainframe which did not support curly braces. I suggested that they could use macros like

#def BEGIN {    
#def END }  

or as a friendlier PL/I alternative

#def BEGIN ??<
#def END ??>

and if they really wanted to get fancy they could try

#ifdef MAINFRAME
    #def BEGIN ??<
    #def END ??>
#else
    #def BEGIN {    
    #def END }  
#endif

and then the program would look like it was written in Pascal. They just looked at me funny and wouldn't speak to me for the rest of the day. I don't think I blame them. :)

What killed the effort what not the tri-graphs, it was the IO system differences between the platforms. Opening files on the PC was so much different than the mainframe it would have introduced way too many kludges to keep the same code running on both.


Some European keyboards don't (didn't?) have all the punctuation characters that US keyboards had, because they needed the keys for their unusual alphabetic characters. So for example (making this up), the Swedish keyboard would have A-ring where the curly brace was.

To accommodate those users, trigraphs are a way to enter punctuation using only the most common ASCII characters.


Primarily because the C standard introduced them back in 1989, when there were issues with the presence of the characters that trigraphs map to on some machines. By the time the C++ standard was published in 1998, the need for trigraphs was not great. They are a wart on C; they are just as much a wart on C++. There was a need for them - especially outside the English-speaking world - which is why they were added to C.


They are there mostly for historical reasons. Nowadays, most modern keyboards for most languages allow access to all those characters, but this used to be a problem once with some European keyboards. This is why trigraphs were invented.

If you don't know what they're for, you shouldn't use them.

It's still good to be aware of them, though, since you might accidentally and unintentionally use one in your code.

참고 URL : https://stackoverflow.com/questions/1234582/purpose-of-trigraph-sequences-in-c

반응형