99

I'm a very experienced C programmer, but recently I came across some code on a mainframe that has a local variable. This is in a simple C function that declares this variable, and then strcpy / strcats two strings into it, and then tries an fopen.

char foo(|10|);

This code is very old. Possibly even K&R C old. I'm wondering if this is some obscure compiler extension or an adaptation to a keyboard that doesn't have [] or something like that.

Anyone know if this declaration is 'special'?

This is a standard Z/OS mainframe. I'm not sure what compiler is used.

gbronner
  • 1,907
  • 24
  • 39
  • 17
    It's an IBM mainframe... is it possible the character encoding is [EBCDIC](https://en.wikipedia.org/wiki/EBCDIC)? If Wikipedia is to be believed, it lacked the `[ ]` characters, so a C compiler meant to work on EBCDIC source may well have had to define some substitute. – Nate Eldredge Dec 15 '22 at 04:39
  • 3
    ... though C defines trigraph sequences for exactly that purpose. But perhaps that's a nonstandard / prestandard alternative. – John Bollinger Dec 15 '22 at 04:43
  • @NateEldredge Could be, but that page also shows `|` as not necessarily present. – dbush Dec 15 '22 at 04:44
  • 10
    This question would be well-received on Retrocomputing.SE as well – Lorraine Dec 15 '22 at 16:07

1 Answers1

108

It seems to be an early or non-standard form of digraph. The code was probably written using EBCDIC instead of ASCII, and EBCDIC doesn't have [ ] characters (at least not in all code pages).

I found the manual for SAS/C, a C compiler apparently meant for System/370. On page 2-10 (page 42 of the pdf) you can see they list (| |) as "alternate forms" for [ ].

(Though apparently | is not in all the code pages either; but maybe it was in a code page that was more commonly used? I don't know.)

C99 also included digraphs (and trigraphs) to solve the same problem, but they used <: :> as the digraphs, and ??( ??) for the trigraphs.

Nate Eldredge
  • 48,811
  • 6
  • 54
  • 82
  • 12
    This appears to be correct. A Google Books searched turned up a barely readable snippet of *Dr. Dobb's Journal* from 1993 that indicated that MVS EBCDIC didn't support `[` and `]` and the digraphs `(|` and `|)` were used instead. – sj95126 Dec 15 '22 at 05:05
  • 4
    Digraphs were added to standard C in C95 (ISO 9899/AMD1:1995). – Lundin Dec 15 '22 at 07:39
  • 2
    Thanks -- this came out of an ebcdic character set mainframe. I had heard of trigraphs (and checked!), but had never heard of digraphs in C code before! – gbronner Dec 15 '22 at 17:46
  • 1
    Trigraphs were removed in the C++17 standard. All the major compilers still have *optional* support for them, though. – dan04 Dec 15 '22 at 19:48
  • 5
    But @dan04 this question is about the C language, not C++. – fabspro Dec 17 '22 at 11:30