error: expected ')' before '*' token -- What is this ?

K

Keith Thompson

Ram Prasad said:
I am trying to write a simple libspf2 plugin code for my postfix
( milter)
I am getting this unhelpful error message when I try to compile

gcc -g1 -Wall -I/usr/local/include/spf2 -I. -c mfunc.c
In file included from mfunc.c:1:
mfunc.c:42: error: expected ')' before '*' token
make: *** [mfunc.o] Error 1

my mfunc.c has on the line 42
-----------------------
. . . . .
SPF_result_t spfcheck_s(SPF_request_t *ecm_spf_request, char* ip,
char* helo, char* sender) {
SPF_response_t *spf_response = NULL;
SPF_result_t t;
SPF_request_set_ipv4_str( ecm_spf_request, ip );
SPF_request_set_helo_dom( ecm_spf_request, helo );
SPF_request_set_env_from( ecm_spf_request, sender );
SPF_request_query_mailfrom(ecm_spf_request, &spf_response);
t = SPF_response_result(spf_response);
SPF_response_free(spf_response);
return t;
}

Typedef names are treated rather oddly in C. Within the compiler, a
typedef name, once it's declared, effectively becomes a keyword rather
than an ordinary identifier. This means that errors with typedef
names can cause bizarre-looking syntax error messages rather than the
"undeclared identifier" message you might expect.

Historical digression:
Early versions of C (before K&R1) didn't have 'typedef', and all
type names were defined by special syntax, not by single
identifiers. 'int', 'double', and so forth are all keywords,
arrays and pointers use special punctuators '[]' and '*',
structure types require a 'struct' keyword, and so forth. When
typedefs were added later on, they had to fit into that model,
which is why they behave so oddly. This can be surprising if
you're accustomed to other languages in which simple identifiers
commonly are used as type names.

For example, here's a small C translation unit with an obvious error:

typedef int my_type;
mytype x;

And here's what gcc has to say about it:

c.c:2: error: parse error before "x"
c.c:2: warning: data definition has no type or storage class

Since "mytype" hasn't been declared as a typedef, the compiler doesn't
even try to guess that it might be a type name, so it throws up its
hands and just fails to parse the declaration. (Possibly it could be
smarter about this, but apparently it isn't.)

I see no obvious errors in the code you posted *assuming* that
SPF_result_t and SPF_request_t have been declared as typedef names.
So, since the compiler is reporting a syntax error, it's likely that
either SPF_result_t or SPF_request_t is *not* declared as a typedef
name, or that neither is.

To test this, try temporarily adding a couple of dummy declarations
above your function definition:

SPF_result_t dummy1;
SPF_request_t dummy2;

and recompile. If I'm right, your compiler will report an equally
confusing syntax error message on one of those lines. Since syntax
errors can cause the compiler to quit trying to process the rest of
the file, try them one at a time. Once you've done that, your job is
to dig into all your nested include files and figure out *why* it's
not declared. Perhaps you haven't included the right header, or
you've misspelled the type name, or the typedef declaration is
excluded by a #if or #ifdef directive. Since the headers you're using
aren't part of the C standard, we can't help you with that.

Seeing the output of the preprocessor could be useful, but beware that
it's going to be very large, since all your headers and macros will be
expanded. gcc uses the "-E" option for this. If you know where your
compiler looks for header files, you might also try searching there
for "SPF_result_t" and/or "SPF_request_t".
 
K

Kenneth Brody

Ram Prasad wrote:
[...]
mfunc.c:42: error: expected ')' before '*' token
[...]

Life imitates art?

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:[email protected]>
 

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

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top