35

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)

10
  • 5
    I'm ... unaware that these pairs of characters ever had a meaning in C. what makes you think that they did? Oct 8, 2009 at 22:40
  • 4
    the logical symbols AND and OR ? Oct 8, 2009 at 22:51
  • 1
    Where in code did you see this? Could you share some lines? Oct 8, 2009 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! Oct 8, 2009 at 23:57
  • 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. Oct 9, 2009 at 5:25

8 Answers 8

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)

1
  • 7
    +1 for weird arcane preprocessor magic. This looks like the kind of thing you might see in an IOCCC entry.
    – Chris Lutz
    Oct 8, 2009 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.

6
  • 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 9, 2009 at 0:06
  • 5
    You probably guess right: I found implementations of the /\ and \/ operators in both Unix V6 & V7. (bitsavers.org/bits/Interdata/32bit/unix/univWollongong_v6/… & 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 9, 2009 at 0:31
  • @NevilleDNZ Good job. See maps.google.com/… Oct 9, 2009 at 0:59
  • 7
    "The internet" says the \ character was added to ASCII by 'Bob Bemer' specifically to allow the /\ and \/ operators. c.f. 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<b)?(a):(b))
    – NevilleDNZ
    Oct 9, 2009 at 1: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. Oct 17, 2009 at 17:22
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.

3
  • 10
    If someone does this in code I have to maintain, they'd damn well have better left the state...
    – T.E.D.
    Oct 8, 2009 at 22:54
  • @T.E.D. - what about splitting the / and the * of a comment over multiple lines by using backslash-newline? Oct 8, 2009 at 23:22
  • 5
    \/ for sup and /\` for inf` are established mathematical notation. See also en.wikipedia.org/wiki/Lattice_%28order%29 Oct 9, 2009 at 2:32
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!
3
  • 1
    The language surprises me once again.
    – GManNickG
    Oct 8, 2009 at 23:11
  • 3
    I saw this when I was browsing through the C99 standard and thought, "Hey that's cool! ... and mostly useless." Oct 8, 2009 at 23:17
  • How many comment matching regular expressions handle this correctly? And does it actually matter, except to compiler writers who have to worry about such details? (Answers: very few, and not really.) Oct 9, 2009 at 23:21
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.

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.

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)

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.

1
  • 1
    I think the OP means the two-character combinations /` and \/` which are even more meaningless.
    – Chris Lutz
    Oct 8, 2009 at 22:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.