Weird syntax error with gcc and FreeBSD

Discussion in 'C Programming' started by =?ISO-8859-15?Q?S=F6nke_Tesch?=, Oct 22, 2003.

  1. Hi everybody,

    I have a problem with the following piece of code:

    141: /* A data block to manage a single log target: */
    142: typedef struct {
    143: apr_reslist_t *dbs; /* connection pool */
    144:
    145: const char *uri; /* the complete log uri.. */

    This compiles fine (using gcc 3.2.2 through Apache 2 apxs) on Linux, but
    it breaks on some other guy's FreeBSD (again using apxs/gcc, but unknown
    gcc version):

    /usr/local/libexec/apache2/mod_log_mysql.c:143: syntax error before
    'apr_reslist_t'

    /usr/local/libexec/apache2/mod_log_mysql.c: In function 'mysql_log_setup':

    /usr/local/libexec/apache2/mod_log_mysql.c:210: structure has no member named
    'dbs'
    [and more "unknown member dbs"..]

    No idea what's wrong with line 142 or 143. At first I thought this might be a
    problem with apr_reslist_t being unknown but after changing apr_reslist_t to
    xxxapr_reslist_t it dumps other errors than the ones above.
    Then I tried a slightly different line 141:

    141: typedef struct s_log_mysql {

    Doesn't help either.

    Any ideas? I cannot imagine that this is some gcc incompatibility, at least
    it seems to me like standard C code.

    The complete mod_log_mysql.c code is available at
    http://bitbrook.de/software/mod_log_mysql/mod_log_mysql.c .

    Thanks a lot, any help appreciated!
    soenk.e
     
    =?ISO-8859-15?Q?S=F6nke_Tesch?=, Oct 22, 2003
    #1
    1. Advertising

  2. Sönke Tesch <> writes:
    > Hi everybody,
    >
    > I have a problem with the following piece of code:
    >
    > 141: /* A data block to manage a single log target: */
    > 142: typedef struct {
    > 143: apr_reslist_t *dbs; /* connection pool */
    > 144:
    > 145: const char *uri; /* the complete log uri.. */
    >
    > This compiles fine (using gcc 3.2.2 through Apache 2 apxs) on Linux, but
    > it breaks on some other guy's FreeBSD (again using apxs/gcc, but unknown
    > gcc version):
    >
    > /usr/local/libexec/apache2/mod_log_mysql.c:143: syntax error before
    > 'apr_reslist_t'


    Presumably apr_reslist_t is a typedef. It looks like you're missing
    the declaration of apr_reslist_t on FreeBSD.

    It's certainly annoying that the compiler gives you a syntax error
    rather than letting you know that apr_reslist_t is an undeclared
    identifier. This is because of the way typedefs are defined in the
    language. Each typedef name is effectively a new keyword. Since
    apr_reslist_t isn't declared, it's just an identifier, and you can't
    use a (non-typedef) identifier as a type name.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
    Schroedinger does Shakespeare: "To be *and* not to be"
     
    Keith Thompson, Oct 23, 2003
    #2
    1. Advertising

  3. Keith Thompson wrote:
    : Sönke Tesch <> writes:

    : > 142: typedef struct {
    : > 143: apr_reslist_t *dbs; /* connection pool */

    : > /usr/local/libexec/apache2/mod_log_mysql.c:143: syntax error before
    : >'apr_reslist_t'

    : Presumably apr_reslist_t is a typedef.

    Yes, it's in the Apache Portable Runtime utilities, apr_reslist.h:

    /** Opaque resource list object */
    typedef struct apr_reslist_t apr_reslist_t;

    The file apr_reslist.h is definitly #included, since everything else
    used from it is accepted. I also doubt that the Apache group made a
    mistake here - at least the Apache webserver is available for FreeBSD,
    so it must work :)

    : It looks like you're missing
    : the declaration of apr_reslist_t on FreeBSD.

    That was my first thought, but gcc prints "parse error" (not "syntax
    error") and three dozens of other messages about missing semicolons
    and other stuff if it encounters an unknown item.
    Here, it just complains about the wrong syntax in line 143 and later
    about the undefined "dbs" field whenever it's accessed (makes sense
    to me since the dbs declaration failed).

    : Since
    : apr_reslist_t isn't declared, it's just an identifier, and you can't
    : use a (non-typedef) identifier as a type name.

    Might there be a problem with the typedef declaration from apr_reslist.h
    quoted above? I have to admit that I do not understand that double
    apr_reslist_t-part there :]

    Regards,
    soenk.e
     
    =?ISO-8859-15?Q?S=F6nke_Tesch?=, Oct 23, 2003
    #3
  4. "Sönke Tesch" <> wrote in message
    news:bn87v4$u791e$-berlin.de...
    > Keith Thompson wrote:
    > : Sönke Tesch <> writes:
    >
    > : > 142: typedef struct {
    > : > 143: apr_reslist_t *dbs; /* connection pool */
    >
    > : > /usr/local/libexec/apache2/mod_log_mysql.c:143: syntax error before
    > : >'apr_reslist_t'
    >
    > : Presumably apr_reslist_t is a typedef.
    >
    > Yes, it's in the Apache Portable Runtime utilities, apr_reslist.h:
    >
    > /** Opaque resource list object */
    > typedef struct apr_reslist_t apr_reslist_t;
    >
    > The file apr_reslist.h is definitly #included, since everything else
    > used from it is accepted. I also doubt that the Apache group made a
    > mistake here - at least the Apache webserver is available for FreeBSD,
    > so it must work :)
    >
    > : It looks like you're missing
    > : the declaration of apr_reslist_t on FreeBSD.
    >
    > That was my first thought, but gcc prints "parse error" (not "syntax
    > error") and three dozens of other messages about missing semicolons
    > and other stuff if it encounters an unknown item.
    > Here, it just complains about the wrong syntax in line 143 and later
    > about the undefined "dbs" field whenever it's accessed (makes sense
    > to me since the dbs declaration failed).
    >
    > : Since
    > : apr_reslist_t isn't declared, it's just an identifier, and you can't
    > : use a (non-typedef) identifier as a type name.
    >
    > Might there be a problem with the typedef declaration from apr_reslist.h
    > quoted above? I have to admit that I do not understand that double
    > apr_reslist_t-part there :]
    >
    > Regards,
    > soenk.e
    >

    take a look at this message - it mentions that the default value(in apr.h)
    for APR_HAS_THREADS is 0(or at least was at one point in history) which
    would exclude the definition of apr_reslist_t - which would probably lead to
    the behavour you are seeing.

    http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/72610
     
    Peter Slootweg, Oct 23, 2003
    #4
  5. "Sönke Tesch" <> wrote in message
    news:bn87v4$u791e$-berlin.de...
    > Keith Thompson wrote:
    > : Sönke Tesch <> writes:
    >
    > : > 142: typedef struct {
    > : > 143: apr_reslist_t *dbs; /* connection pool */
    >
    > : > /usr/local/libexec/apache2/mod_log_mysql.c:143: syntax error before
    > : >'apr_reslist_t'
    >
    > : Presumably apr_reslist_t is a typedef.
    >
    > Yes, it's in the Apache Portable Runtime utilities, apr_reslist.h:
    >
    > /** Opaque resource list object */
    > typedef struct apr_reslist_t apr_reslist_t;


    (snip)

    > : Since
    > : apr_reslist_t isn't declared, it's just an identifier, and you can't
    > : use a (non-typedef) identifier as a type name.
    >
    > Might there be a problem with the typedef declaration from apr_reslist.h
    > quoted above? I have to admit that I do not understand that double
    > apr_reslist_t-part there :]


    It typedefs the type (struct apr_reslist_t) to apr_reslist_t, which saves
    having to type struct all over. The struct namespace is separate from the
    typedef namespace, so you can do that. Though if struct apr_reslist_t isn't
    defined, then the typedef won't work.

    It might be that you are allowed to typedef the struct before defining the
    struct, so that the compiler wouldn't issue an error message yet.

    -- glen
     
    Glen Herrmannsfeldt, Oct 24, 2003
    #5
  6. Peter Slootweg wrote:
    : take a look at this message - it mentions that the default value(in apr.h)
    : for APR_HAS_THREADS is 0(or at least was at one point in history) which
    : would exclude the definition of apr_reslist_t - which would probably lead to
    : the behavour you are seeing.

    No, #if is already used instead of #ifdef, that wasn't the problem.

    Despite the different error messages on FreeBSD and Linux the problem was in
    fact a missing apr_reslist_t declaration, just as Keith already mentioned.
    The cause is that Apache Portable Runtime thread support is normally disabled
    on FreeBSD because of some incompatibility. apr_reslist however depends on
    threads, so they excluded the complete apr_reslist with '#if APR_HAS_THREADS'.
    That's why compilation fails on FreeBSD but not on Linux.

    But thanks anyway, Keith, Peter and Glen!
    soenk.e
     
    =?ISO-8859-1?Q?S=F6nke_Tesch?=, Oct 24, 2003
    #6
    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. Serpent

    GCC on FreeBSD - C and ASM

    Serpent, Jul 21, 2004, in forum: C Programming
    Replies:
    3
    Views:
    665
    brian
    Jul 22, 2004
  2. Razvan Cojocaru
    Replies:
    1
    Views:
    460
  3. Akira Kitada
    Replies:
    0
    Views:
    723
    Akira Kitada
    Oct 25, 2008
  4. M.-A. Lemburg
    Replies:
    0
    Views:
    400
    M.-A. Lemburg
    Oct 25, 2008
  5. Akira Kitada
    Replies:
    0
    Views:
    661
    Akira Kitada
    Oct 25, 2008
Loading...

Share This Page