4

I have been tasked with converting a C program from an iSeries/AS400 into .NET. It's been awhile since I've looked at C, and I've never used C on an iSeries before. I'm seeing items such as

main(int argc, char *argv ??(??))

I'm unsure what the ?? is for. Based upon the usage here, I would assume it is for arrays, but wanted to make sure before I go down the wrong path.

Dave Simione
  • 1,441
  • 2
  • 21
  • 31
  • 4
    http://en.wikipedia.org/wiki/Digraphs_and_trigraphs#C should help you – StephenTG Aug 01 '13 at 14:34
  • 3
    It's trigraph. `??(` is `[` and `??)` is `]`. – johnchen902 Aug 01 '13 at 14:34
  • 4
    Now I'm wondering what grudge the person who wrote it in the first place had against their successors... – StephenTG Aug 01 '13 at 14:35
  • Why not post these comments as answers? – crashmstr Aug 01 '13 at 14:35
  • I suppose I will. Give me a minute – StephenTG Aug 01 '13 at 14:35
  • 2
    possible duplicate of [Unknown meta-character in C/C++ string literal?](http://stackoverflow.com/questions/1669448/unknown-meta-character-in-c-c-string-literal) – alk Aug 01 '13 at 14:37
  • 2
    Trigraphs were from a time when there were a significant number of terminals with keyboards that didn't have some of the characters (the square braces in this case). I'm guessing this code was ported from some older system onto the AS/400 and the trigraphs are hold-overs. You should be able to create some regular expressions to globally replace them in your project. – Speed8ump Aug 01 '13 at 15:39

2 Answers2

7

??( is equivalent to [ and ??) is equivalent to ]. These are called trigraphs, and they're replaced by the preprocessor before anything else is done with the code. Here's a list of other trigraphs.

StephenTG
  • 2,579
  • 6
  • 26
  • 36
  • 1
    Funny story: I only knew this answer because bad spelling in a comment from someone's code I was editing led me to ask this question on meta: http://meta.stackexchange.com/questions/191267/is-it-ok-to-edit-comments-in-code – StephenTG Aug 01 '13 at 14:40
3

It's called Trigraph:

C11(ISO/IEC 9899:201x) §5.2.1.1 Trigraph sequences

Before any other processing takes place, each occurrence of one of the following sequences of three characters (called trigraph sequences17)) is replaced with the corresponding single character.

??=    #
??(    [
??/    \
??)    ]
??'    ^
??<    {
??!    |
??>    }
??-    ~

So the code

main(int argc, char *argv ??(??))

turns to

main(int argc, char *argv [])
Yu Hao
  • 119,891
  • 44
  • 235
  • 294