recently I ran into a strange grammar of C Programming Language.
First, let's see the code:
main(void) {
int a[10:> ;
printf("asdf");
return 0;
}
And you can compile it with gcc:
/tmp gcc sample.c
sample.c: In function ‘main’:
sample.c:3: warning: incompatible implicit declaration of built-in function ‘printf’
As you can see, there's no error or any warning related to it. So this means :>
equals to ]
in CPL?
How can that happen?
BTW: I'm using gcc 4.2.1.
Yes, this works.
It's called a digraph and was invented because in the old days (mid-1990s) there were still people using serial terminals (kind of like a PC, but without local processing), and some of those used a 7-bit character set. It was derived from ASCII, however where ASCII had [
and ]
, the derived character set would instead have other glyphs (e.g, Å and Ä).