34

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)
NevilleDNZ
  • 1,269
  • 12
  • 31
  • 5
    I'm ... unaware that these pairs of characters ever had a meaning in C. what makes you think that they did? – Brian Postow Oct 08 '09 at 22:40
  • 4
    the logical symbols `AND` and `OR` ? – Nick Dandoulakis Oct 08 '09 at 22:51
  • 1
    Where in code did you see this? Could you share some lines? – Dirk Vollmar Oct 08 '09 at 23:07
  • 5
    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. And, in those days, it was probable that the modern '`+=`' operators were still written as '`=+`' and were in fact two tokens, so the hypothetical '`a =/\ b;`' would have been the max-assignment operator, etc. Intriguing! – Jonathan Leffler Oct 08 '09 at 23:57
  • 1
    It also occurs to me that Thompson's ACM Turing Award speech 'Reflections On Trusting Trust' (http://www.ece.cmu.edu/~ganger/712.fall02/papers/p761-thompson.pdf) is somehow relevant. – Jonathan Leffler Oct 09 '09 at 00:08
  • 1
    @Jonathan Leffler: without the full context of the code it's hard to be sure, but it *looks* like `\/` was MAX and `/\\` was `MIN`. Probably not the direction I would have chosen! – Greg Hewgill Oct 09 '09 at 00:25
  • @Greg - yup...I suspect you're correct. Maybe that was why it was never standardized? – Jonathan Leffler Oct 09 '09 at 00:26
  • @Jonathan: quite possibly. Not to mention the confusion with the standard symbols for logical AND and OR as Nick D mentions above. – Greg Hewgill Oct 09 '09 at 00:38
  • 12
    +1 for the most interesting question I've come across that started out looking like one of the goofiest. I'd never heard of these operators before - if only they had stuck we'd have been saved years of headaches having to deal with crappy MIN/MAX macros that evaluated operands twice. – Michael Burr Oct 09 '09 at 05:25
  • I don't believe I've ever seen those operators anywhere. Ever. – Nick Bedford Oct 08 '09 at 22:43

8 Answers8

18

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)

Tamas Czinege
  • 118,853
  • 40
  • 150
  • 176
  • 7
    +1 for weird arcane preprocessor magic. This looks like the kind of thing you might see in an IOCCC entry. – Chris Lutz Oct 08 '09 at 22:45
14

\/ 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.

Derek 朕會功夫
  • 92,235
  • 44
  • 185
  • 247
Sinan Ünür
  • 116,958
  • 15
  • 196
  • 339
  • 3
    This reminds me of the deprecated and >? (min and max) operators and their assignment variants = and >?= that G++ used to allow and that I've had the misfortune of encountering. – Joey Adams Oct 09 '09 at 00:06
  • 5
    You probably guess right: I found implementations of the /\ and \/ operators in both Unix V6 & V7. (http://www.bitsavers.org/bits/Interdata/32bit/unix/univWollongong_v6/interdata_v6/usr/source/c/c00.c & http://stuff.mit.edu/afs/sipb/project/v7unix/fs/usr/src/cmd/c/c00.c). I appears that K&R forgot to document /\ and \/ when they wrote the old testament. Now all I need to know is where TH is Wollongong? ;-) – NevilleDNZ Oct 09 '09 at 00:31
  • @NevilleDNZ Good job. See http://maps.google.com/maps?q=Wollongong&oe=utf-8&rls=org.mozilla:en-US:official&client=firefox-a&um=1&ie=UTF-8&hq=&hnear=Wollongong+NSW,+Australia&gl=us&ei=u4rOSpfDFZLVlAfa2KypCg&sa=X&oi=geocode_result&ct=title&resnum=1 – Sinan Ünür Oct 09 '09 at 00:59
  • 7
    "The internet" says the \ character was added to ASCII by 'Bob Bemer' specifically to allow the /\ and \/ operators. c.f. http://home.ccil.org/~remlaps/www.bobbemer.com/BRACES.HTM - Maybe sometimes - even to this day - MIN and MAX are implemented in C with precarious side effects: eg #define MIN(a,b) ((a – NevilleDNZ Oct 09 '09 at 01:51
  • 1
    Just curious -why were the terms 'sup' and 'inf' used instead of what I'd think were the more immediately understandable 'max' and 'min'? The linked pages describing 'Supremum' and 'Infimum' make my head hurt. – Michael Burr Oct 17 '09 at 17:22
  • Because, in general, a maximum and a minimum of a set don't need to exists. For example, `[0,1)` has not maximum but its supremum is well defined. See also http://en.wikipedia.org/wiki/Lattice_%28order%29 and associated references. – Sinan Ünür Oct 17 '09 at 20:54
10

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.

Community
  • 1
  • 1
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
6

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!
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Cristián Romo
  • 9,814
  • 12
  • 50
  • 50
3

C has never had those operators.

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

Cade Roux
  • 88,164
  • 40
  • 182
  • 265
3

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.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
3

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)

Quintus
  • 470
  • 3
  • 10
1

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.

T.E.D.
  • 44,016
  • 10
  • 73
  • 134