Don't understand syntax error

C

Chris Saunders

I'm getting this error report from my compiler (MSVC++ 7):

c:\Eiffel55\library\cjs\pdf\spec\include\p_intern.h(258) : error C2143:
syntax error : missing ')' before '*'

Here's the code:


struct PDF_s {
/* -------------------------- general stuff ------------------------ */
unsigned long magic; /* poor man's integrity check */
void (*freeproc)(PDF *p, void *mem);
pdc_core *pdc; /* core context */
....
....
};

I removed all code one line after the error line.
The reported error line is:

void (*freeproc)(PDF *p, void *mem);

I am not an expert in C but I believe I have a reasonable understanding
but I cannot see a problem with this line.

Could anyone help?
 
A

Alex Fraser

Chris Saunders said:
I'm getting this error report from my compiler (MSVC++ 7):

c:\Eiffel55\library\cjs\pdf\spec\include\p_intern.h(258) : error C2143:
syntax error : missing ')' before '*'

Here's the code: [snip]
The reported error line is:

void (*freeproc)(PDF *p, void *mem);

Because the code you provided is incomplete, it seems that only a guess is
possible. My guess, FWIW, is that it has something to do with "PDF".

Alex
 
B

baumann@pan

Chris said:
I'm getting this error report from my compiler (MSVC++ 7):

c:\Eiffel55\library\cjs\pdf\spec\include\p_intern.h(258) : error C2143:
syntax error : missing ')' before '*'

what's the line of 258?

maybe you have to declare the PDF struct before struct PDF_s
 
A

Achintya

Chris said:
I'm getting this error report from my compiler (MSVC++ 7):

c:\Eiffel55\library\cjs\pdf\spec\include\p_intern.h(258) : error C2143:
syntax error : missing ')' before '*'

Here's the code:


struct PDF_s {
/* -------------------------- general stuff ------------------------ */
unsigned long magic; /* poor man's integrity check */
void (*freeproc)(PDF *p, void *mem);
pdc_core *pdc; /* core context */
...
...
};

I removed all code one line after the error line.
The reported error line is:

void (*freeproc)(PDF *p, void *mem);

I am not an expert in C but I believe I have a reasonable understanding
but I cannot see a problem with this line.

Could anyone help?

Hi,

I think the line...
void (*freeproc)(PDF *p, void *mem);

should be...

void (*freeproc)(struct PDF *p, void *mem);

I haven't tried compiling since I donot have VC 7.

-vs_p
 
J

Jaspreet

I am just making a guess here.

Have you already declared PDF before using it in
void (*freeproc)(PDF *p, void *mem);

It would help if you could let us have the defintion of PDF ?

Having a struct keyword or not before PDF should not make a difference
though.
 
C

Chris Torek

[snippage]
struct PDF_s {
void (*freeproc)(PDF *p, void *mem);
};

[produces a syntax error on the middle of the three above lines]
Could anyone help?

See <http://web.torek.net/torek/c/types2.html>, paying particular
attention to the ordering rules for using typedefs (near the bottom
of the article). The typedef line I see in my crystal ball:

typedef struct PDF_s PDF;

must come *before* the definition of the structure.
 
K

Keith Thompson

Jaspreet said:
I am just making a guess here.

Have you already declared PDF before using it in
void (*freeproc)(PDF *p, void *mem);

It would help if you could let us have the defintion of PDF ?

Having a struct keyword or not before PDF should not make a difference
though.

Yes, it does. If you have a type "struct PDF", you can't refer to it
as "PDF", unless PDF happens to be a typedef for struct PDF. If your
compiler allows you to do so, it's not a C compiler (it's probably a
C++ compiler).

In the code fragment posted by the OP, there's nothing called either
"PDF" or "struct PDF", just a "struct PDF_s".
 
J

Jaspreet

Keith said:
Yes, it does. If you have a type "struct PDF", you can't refer to it
as "PDF", unless PDF happens to be a typedef for struct PDF. If your
compiler allows you to do so, it's not a C compiler (it's probably a
C++ compiler).
I agree to your statement. However, I guess you canot have a function
decl. inside a struct in C. Let me know what I am missing here. I am
using gcc 3.3.2. If I make the file as .c file the compiler complains
about
field declared as a function.

However changing the extension to .cc lets me compile correctly.

So to summarise a function block inside a struct is not allowed in C.
Let me know if I am wrong.
 
K

Keith Thompson

Jaspreet said:
I agree to your statement. However, I guess you canot have a function
decl. inside a struct in C. Let me know what I am missing here. I am
using gcc 3.3.2. If I make the file as .c file the compiler complains
about
field declared as a function.

However changing the extension to .cc lets me compile correctly.

So to summarise a function block inside a struct is not allowed in C.
Let me know if I am wrong.

It's correct that you can't declare a function inside a struct declaration.

As for what C++ allows, that's a question for comp.lang.c++ (or,
better yet, for your C++ textbook).
 
C

CBFalconer

Jaspreet said:
.... snip ...

I agree to your statement. However, I guess you canot have a
function decl. inside a struct in C. Let me know what I am
missing here. I am using gcc 3.3.2. If I make the file as .c file
the compiler complains about field declared as a function.

However changing the extension to .cc lets me compile correctly.

No it doesn't. It just causes the compiler to treat it as C++,
which is another language and has different rules. We don't
discuss C++ here.

--
Some informative links:
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html
 

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,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top