What _did_ the C operators /\ and \/ do?

2.6k views Asked by At

Anyone can "declare" ones own operators in C.... that is if one is a C compiler guru and has the source code to the C compiler! ;-)

Further questions to puzzle:

  1. How are these operations done in C99? gcc? ...
  2. And why were /\ & \/ dropped?
  3. Which types were the /\ and \/ operators valid for?

Googling for "/\ \/" naturally returns nothing. Wikipedia has a page for neither /\ nor \/. But I have spotted form similar operators are built into the XML character entities!


Source added: I found the offending example in the PDP's cc source file "c00.c":

/*
 * Return the next symbol from the input.
 * peeksym is a pushed-back symbol, peekc is a pushed-back
 * character (after peeksym).
 * mosflg means that the next symbol, if an identifier,
 * is a member of structure or a structure tag or an enum tag
 */
symbol()
{
...
 case BSLASH:
  if (subseq('/', 0, 1))
   return(MAX);
  goto unkn;

 case DIVIDE:
  if (subseq('\\', 0, 1))
   return(MIN);
  if (subseq('*',1,0))
   return(DIVIDE);
...
}


Actual Implementations: The /\ and \/ operators date back as far as Sixth Edition Unix 1975 (so far). Examples: Unix V6(1975), Unix V7(1979) and more currently BSD 2.11(1992-2008)

8

There are 8 answers

6
Sinan Ünür On BEST ANSWER

\/ looks like sup and /\ looks like inf. They could also be and , respectively.

I don't remember ever seeing these in K&R 2nd edition or any other C book.

1
Tamas Czinege On

Neither /\ nor / are defined as operators in the ISO C89 standard, and I don't think they were ever defined in any earlier version. And they are definitely not defined in C99 as far as I know.

Here's a draft of the ANSI C89 standard, for reference: http://flash-gordon.me.uk/ansi.c.txt

(You are likely a victim of some weird arcane preprocessor magic)

0
Cade Roux On

C has never had those operators.

Typically / would be an escape code in some string systems, not sure that /\ has ever had any meaning.

1
T.E.D. On

The Caret (^) performs a bitwise exclusive or.

I don't believe there is a "V" operator. That's the letter 'V' (or something that looks a whole heck of a lot like it). Somebody might want to name a variable that.

3
Jonathan Leffler On

Speculation!

If you have spaces around them, then:

a /\ b   ===>   a / b

a \/ b   ===>   a / b

Logic: the preprocessing phase has to deal with backslash and a character after, and is quite likely to treat backslash-space as space, and backslash-slash as slash.

That said, both the SUN C compiler (version 12) and GNU C compiler (version 4.4) reject code containing the backslash. But I could easily believe that old, pre-standard C preprocessors were less careful about it.

Standards compliance

The operators have never been part of an official version of C.

Also, the standard would not allow the interpretation I gave (section 5.1.1.2 Translation phases, in both C89 and C99) - but non-standard compilers are not constrained by the standard, of course.


Added after the source was posted:

Interesting! So it looks plausible for 'a = b /\ c;' to assign the maxiumum of b and c to a, and 'a = b \/ c;' to do the minimum (or, as Greg Hewgill pointed out, more likely vice versa). And, in those days, it was probable that the modern '+=' operators were still written as '=+' and were in fact two tokens (no supporting evidence for this assertion; failing memory again), so the hypothetical 'a =/\ b;' (or, in modern notation, 'a /\= b;') would have been the max-assignment operator, etc.

It also occurs to me that Thompson's ACM Turing Award speech 'Reflections On Trusting Trust' is somehow relevant.

0
Jerry Coffin On

I doubt they ever meant anything. If they ever did, it was a long time ago. The only major operators I know of that have been removed from C were =+ and =-, which were early synonyms for += and -=. You might want to look at DMR's Primeval C Page for evidence.

3
Cristián Romo On

I'm not sure about \/, but /\ is a valid construct. It is used to place the two slashes of a single line comment on separate lines. For example:

/\
/ Comment content

This works because the backslash character escapes the newline and the parser continues as if it wasn't there. This will not work if there is a space after the backslash or if the second forward slash is indented. Because of this, it is possible to escape as many newlines as you like, as in

/\
\
\
\
\
/ Still a legal comment.

Backslashes can also be used at the end of regular single line comments to make them continue to the next line, as in

// Yet another comment \
This line is in the comment \\
And so is this one!
0
Quintus On

I'm going to guess that these are a reference to formal symbolic logic:

http://en.wikipedia.org/wiki/Table_of_logic_symbols

/ is used to denote disjunction (OR) /\ is used (less frequently) to denote conjunction (AND)