12

So I came across this piece of code:

%:include <stdio.h>

int main(int argc, char *argv<::>) <%
    printf("C program succesfully running...");
    getchar();

    return 0;
%>

Is this some compiler bug or is this something new I have not discovered yet because it is running without any problems.

4 Answers4

13

This code uses C digraphs, as explained here: http://en.wikipedia.org/wiki/Digraphs_and_trigraphs#C

The C standard (ISO/IEC 9899:201x, Punctuators §6.4.6:3) has this to say on the matter:

In all aspects of the language, the six tokens

<: :> <% %> %: %:%:

behave, respectively, the same as the six tokens

[ ] { } # ##

except for their spelling.

David Heffernan
  • 587,191
  • 41
  • 1,025
  • 1,442
1

These are punctuators and %: is the same as # and %> is the same as } etc... The C99 draft standard section 6.4.6 Punctuators says:

In all aspects of the language, the six tokens67)

 <:  :> <%   %> %:  %:%:

behave, respectively, the same as the six tokens

  [   ] {    }   #   ##

They are also sometimes refereed to as digraphs as we see in note 67:

These tokens are sometimes called ‘‘digraphs’’.

Community
  • 1
  • 1
Shafik Yaghmour
  • 148,593
  • 36
  • 425
  • 712
1

It is all a very Zen little corner of the C language.

In the olden days, terminals and keyboards often didn't support all the characters one might want for programming; so digraphs and trigraphs were introduced.

I'm surprised any modern compiler still supports them, but there it is.

Williham Totland
  • 27,735
  • 5
  • 49
  • 68
1

Digraph, introduced in C99.

C99 6.4.6 Punctuators

In all aspects of the language, the six tokens

<: :> <% %> %: %:%:

behave, respectively, the same as the six tokens

[ ]  {} # ##

except for their spelling.

Yu Hao
  • 115,525
  • 42
  • 225
  • 281