Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this ->> an old operator or a typo/error?

In the course of my reading I came accross WG14 Defect Report #51 written in 1993 (or perhaps 1893, they left off the century and millennium). In the code sample there, apparently an operator spelled ->> is used on a pointer to a struct. I can't find it in any operator precedence tables I've found, so I am wondering, is or was it ever an operator, and if so, what does (or did, as the case may be) this operator do?

At first I thought it was a typo, but it is reproduced twice more in the text and another time in the code sample in the response to the question, and I have a hard time believing it just slipped past at least two C experts without being noticed, when it jumped out at a novice like me. It's also at the focal point of the code, very easy to notice, and was never corrected.

Here is the code with added indentation:

#include <stdlib.h>  struct A {     char x[1]; };  main() {     struct A *p = (struct A *) malloc(sizeof(struct A) + 100);     p->>x[5] = '?';  /* This is the key line [for both them and us] */     return 0; } 

I tried to compile this code with both a C and C++ compiler and it failed to parse in either one. Perhaps this was some operator in an early version of C that isn't used any more?

This feels suspiciously like the What is the name of this operator: "-->"? question, but I don't think this is a combination of two other operators, I don't see how it can be divided up and be valid.

like image 350
Seth Carnegie Avatar asked Oct 24 '12 13:10

Seth Carnegie


2 Answers

It looks like a problem in the transcription process. There is a similar problem in DR 42, where the greater than sign is doubled: http://www.open-std.org/jtc1/sc22/wg14/docs/rr/dr_042.html

like image 121
Vaughn Cato Avatar answered Sep 19 '22 21:09

Vaughn Cato


I learned C in 1992, and I'm 100% certain there was no such operator back then.

From the context, p->>x[5], we can deduce that it appears to do exactly the same thing as the more familiar arrow operator, ->. It is therefore likely to be a typo.


Alternatively, it could be an encoding issue in transcribing the code into HTML. If you look at the source to that page, you can see it's got a strange mixture of escape codes and literal < and > characters:

<TT><B>#include &lt;stdlib.h><BR> 
like image 43
Graham Borland Avatar answered Sep 21 '22 21:09

Graham Borland