Don't understand syntax error

Discussion in 'C Programming' started by Chris Saunders, May 16, 2005.

  1. 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?


    --
    Regards
    Chris Saunders
    Chris Saunders, May 16, 2005
    #1
    1. Advertising

  2. Chris Saunders

    Alex Fraser Guest

    "Chris Saunders" <> wrote in message
    news:dtYhe.574$...
    > 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
    Alex Fraser, May 16, 2005
    #2
    1. Advertising

  3. Chris Saunders

    baumann@pan Guest

    Chris Saunders wrote:
    > 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

    >
    > 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?
    >
    >
    > --
    > Regards
    > Chris Saunders
    baumann@pan, May 16, 2005
    #3
  4. Chris Saunders

    Achintya Guest

    Chris Saunders wrote:
    > 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?
    >
    >
    > --
    > Regards
    > Chris Saunders


    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
    Achintya, May 16, 2005
    #4
  5. Chris Saunders

    Jaspreet Guest

    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.
    Jaspreet, May 16, 2005
    #5
  6. Chris Saunders

    Chris Torek Guest

    In article <dtYhe.574$>
    Chris Saunders <> wrote:

    [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.
    --
    In-Real-Life: Chris Torek, Wind River Systems
    Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
    email: forget about it http://web.torek.net/torek/index.html
    Reading email is like searching for food in the garbage, thanks to spammers.
    Chris Torek, May 16, 2005
    #6
  7. "Jaspreet" <> writes:
    > 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".

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, May 16, 2005
    #7
  8. Chris Saunders

    Jaspreet Guest

    Keith Thompson wrote:
    > "Jaspreet" <> writes:
    > > 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).
    >

    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.
    Jaspreet, May 17, 2005
    #8
  9. "Jaspreet" <> writes:
    [...]
    > 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).

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, May 17, 2005
    #9
  10. Chris Saunders

    CBFalconer Guest

    Jaspreet wrote:
    >

    .... 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:
    news:news.announce.newusers
    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
    CBFalconer, May 17, 2005
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stef Mientki
    Replies:
    0
    Views:
    570
    Stef Mientki
    Oct 20, 2008
  2. Terry Reedy
    Replies:
    0
    Views:
    683
    Terry Reedy
    Oct 20, 2008
  3. Antoon Pardon

    I don't understand this syntax error

    Antoon Pardon, Jan 19, 2009, in forum: Python
    Replies:
    1
    Views:
    250
    Peter Otten
    Jan 19, 2009
  4. Albert Schlef

    Syntax error I don't understand

    Albert Schlef, Dec 28, 2008, in forum: Ruby
    Replies:
    9
    Views:
    217
    Brian Candler
    Dec 28, 2008
  5. Larry

    Don't understand this syntax -

    Larry, Feb 16, 2005, in forum: Perl Misc
    Replies:
    8
    Views:
    115
    John W. Krahn
    Feb 17, 2005
Loading...

Share This Page