R
Ray Dillinger
Hi. I'm having a problem and I really want to understand it.
Here's the situation: I have an array of pointers, and each
pointer is the head of a linked list of structs. The structs
are typedef'd to have the type name 'event.' It's a simple
open hash table used to implement events in a game.
So, I have a routine that returns the address of one of the
pointers in the array, or returns NULL for a key out of
range (meaning no bucket for that key exists in the table).
Then I try to write this routine:
void test (int key)
{
event **bucket = getbucket(key);
if ((bucket != NULL) && (bucket* != NULL)) /*syntax error?!*/
{
...do stuff ...
}
} /* unmatched '}' at top level?! */
and bizarre stuff happens. First, the compiler (gcc)
reports a 'syntax error before the '*' token' on the
indicated line. Second, it reports an unmatched bracket
at top level at the next indicated line.
I'm baffled and I don't understand. My editor (emacs, in
c mode) reads the brackets the same way I do - indents them
in a way I agree with and reports that they match what it
looks to me like they match. The compiler loses the level
of bracketing somewhere, and since I also am baffled by
the syntax error of the ** pointer, I suspect they may have
the same cause.
But no clue as to what the cause is. Anybody got any insight?
Bear
Here's the situation: I have an array of pointers, and each
pointer is the head of a linked list of structs. The structs
are typedef'd to have the type name 'event.' It's a simple
open hash table used to implement events in a game.
So, I have a routine that returns the address of one of the
pointers in the array, or returns NULL for a key out of
range (meaning no bucket for that key exists in the table).
Then I try to write this routine:
void test (int key)
{
event **bucket = getbucket(key);
if ((bucket != NULL) && (bucket* != NULL)) /*syntax error?!*/
{
...do stuff ...
}
} /* unmatched '}' at top level?! */
and bizarre stuff happens. First, the compiler (gcc)
reports a 'syntax error before the '*' token' on the
indicated line. Second, it reports an unmatched bracket
at top level at the next indicated line.
I'm baffled and I don't understand. My editor (emacs, in
c mode) reads the brackets the same way I do - indents them
in a way I agree with and reports that they match what it
looks to me like they match. The compiler loses the level
of bracketing somewhere, and since I also am baffled by
the syntax error of the ** pointer, I suspect they may have
the same cause.
But no clue as to what the cause is. Anybody got any insight?
Bear