Double Colon in Linked List Access

K

KevinSimonson

I had a job interview yesterday in which I was asked to find as many
bugs as possible in a section of C code. Part of the code said:

struct Node
{ struct Node* next;
int data;
};

and later a variable was declared

struct Node** xyz;

and later on in the code an expression included the phrase "xyz::next"
which as far as I could tell was the equivalent of "(*xyz)->next". Is
this a legal use of the "::" operator? I wasn't aware that the "::"
operator was even _legal to use_ in C; I thought it was a C++
operator. Any input on this would be greatly appreciated.

---Kevin Simonson

"You'll never get to heaven, or even to LA,
if you don't believe there's a way."
from _Why Not_
 
K

Keith Thompson

KevinSimonson said:
I had a job interview yesterday in which I was asked to find as many
bugs as possible in a section of C code. Part of the code said:

struct Node
{ struct Node* next;
int data;
};

and later a variable was declared

struct Node** xyz;

and later on in the code an expression included the phrase "xyz::next"
which as far as I could tell was the equivalent of "(*xyz)->next". Is
this a legal use of the "::" operator? I wasn't aware that the "::"
operator was even _legal to use_ in C; I thought it was a C++
operator. Any input on this would be greatly appreciated.

C has no "::" operator, and there are no contexts in which two ':'
delimiters can be adjacent.
 
M

Morris Keesan

Is this a legal use of the "::" operator? I wasn't aware that the "::"
operator was even _legal to use_ in C; I thought it was a C++
operator. Any input on this would be greatly appreciated.

There is no :: operator in C. As far as I can tell, the only legal uses
of that
character sequence in C would be as part of a string constant, or as part
of a
multi-character character constant.

(I'm sure I'll be corrected if I'm wrong, but outside of string and
character
constants, it appears that the only uses of the character ':' are
* following a label
* as part of the tokens <: :> %: and %:%: , which are equivalent to
[ ] # and ##
* as part of the ?: ternary operator
* preceding the width of a bit-field
* in a preprocessor directive that results in one of the above
)
 
F

Flash Gordon

Morris said:
Is this a legal use of the "::" operator? I wasn't aware that the "::"
operator was even _legal to use_ in C; I thought it was a C++
operator. Any input on this would be greatly appreciated.

There is no :: operator in C. As far as I can tell, the only legal uses
of that
character sequence in C would be as part of a string constant, or as
part of a
multi-character character constant.

(I'm sure I'll be corrected if I'm wrong, but outside of string and
character
constants, it appears that the only uses of the character ':' are
* following a label
* as part of the tokens <: :> %: and %:%: , which are equivalent to
[ ] # and ##
* as part of the ?: ternary operator
* preceding the width of a bit-field
* in a preprocessor directive that results in one of the above
)

OK, here are some more...
* In a comment
* In a #error directive
* As part of a filename in a #include directive
 
G

Guest

|> I had a job interview yesterday in which I was asked to find as many
|> bugs as possible in a section of C code. Part of the code said:
|>
|> struct Node
|> { struct Node* next;
|> int data;
|> };
|>
|> and later a variable was declared
|>
|> struct Node** xyz;
|>
|> and later on in the code an expression included the phrase "xyz::next"
|> which as far as I could tell was the equivalent of "(*xyz)->next". Is
|> this a legal use of the "::" operator? I wasn't aware that the "::"
|> operator was even _legal to use_ in C; I thought it was a C++
|> operator. Any input on this would be greatly appreciated.
|
| C has no "::" operator, and there are no contexts in which two ':'
| delimiters can be adjacent.

They can in a definition where normally [] would be specified, but are
instead replaced by the digraphs <: and :> to form <::>
 
K

Keith Thompson

|> I had a job interview yesterday in which I was asked to find as many
|> bugs as possible in a section of C code. Part of the code said:
|>
|> struct Node
|> { struct Node* next;
|> int data;
|> };
|>
|> and later a variable was declared
|>
|> struct Node** xyz;
|>
|> and later on in the code an expression included the phrase "xyz::next"
|> which as far as I could tell was the equivalent of "(*xyz)->next". Is
|> this a legal use of the "::" operator? I wasn't aware that the "::"
|> operator was even _legal to use_ in C; I thought it was a C++
|> operator. Any input on this would be greatly appreciated.
|
| C has no "::" operator, and there are no contexts in which two ':'
| delimiters can be adjacent.

They can in a definition where normally [] would be specified, but are
instead replaced by the digraphs <: and :> to form <::>

Oh, good catch! (And totally irrelevant to the OP's question,
but you know that.)

I'm going to partially weasel out of it, though. When I wrote
"delimiter", I actually meant to write "punctuator", I just forgot
which term the standard uses. Each of <: and :> is a single
punctuator; the ':' characters, by themselves are not punctuators
in that context.

But the possibilities for obfuscation are nearly endless.

%:
int main(int argv,char*argc<::>)<%%>
%:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top