What is the meaning of char foo(|10|) in C?
Asked Answered
T

1

100

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.

Texas answered 15/12, 2022 at 4:12 Comment(4)
It's an IBM mainframe... is it possible the character encoding is 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.Cannes
... though C defines trigraph sequences for exactly that purpose. But perhaps that's a nonstandard / prestandard alternative.Uintathere
@NateEldredge Could be, but that page also shows | as not necessarily present.Fellmonger
This question would be well-received on Retrocomputing.SE as wellVegetarian
C
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.

Cannes answered 15/12, 2022 at 4:50 Comment(5)
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.Debark
Digraphs were added to standard C in C95 (ISO 9899/AMD1:1995).Aqueous
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!Texas
Trigraphs were removed in the C++17 standard. All the major compilers still have optional support for them, though.Cali
But @Cali this question is about the C language, not C++.Ethyl

© 2022 - 2024 — McMap. All rights reserved.