3

In an answer to another question, someone jokingly mentioned using <: :> instead of [] for array subscripting. I had never heard of this, and apparently neither has Google, so I did a bit of testing and found that all the way back in C compilers, <: is interchangable with [ and :> is interchangable with ], IE:

int* ptr;
ptr<:0:>;
ptr<:0];
ptr[0:>;

All compile and mean the same thing. What was the purpose of this operator?

IllusiveBrian
  • 3,105
  • 2
  • 14
  • 17
  • 3
    To be able to use array syntax in ancient terminals that were not capable of outputting the bracket characters. – Jon Jan 05 '15 at 16:33
  • When C was invented in the 70s. keyboards weren't standardized yet, so some keyboards didn't have all the keys. It probably is another example of that. – sashoalm Jan 05 '15 at 16:34
  • 3
    Because it is so much more readable thant `ptr??(0??)`? – Jonathan Leffler Jan 05 '15 at 16:34
  • @sashoalm: the trigraphs were an invention of ISO (ANSI) C to deal with the fact that European code sets used the code points for characters such as `[]{}` for national alphabetic characters. Digraphs were a later invention (1994 Amd 1, IIRC) for a limited subset of the same job. – Jonathan Leffler Jan 05 '15 at 16:36
  • http://en.wikipedia.org/wiki/Digraphs_and_trigraphs gives a good history and list of digraphs and trigraphs in C and C++. – dho Jan 05 '15 at 21:27

0 Answers0