Weird syntax error with gcc and FreeBSD

  • Thread starter =?ISO-8859-15?Q?S=F6nke_Tesch?=
  • Start date
?

=?ISO-8859-15?Q?S=F6nke_Tesch?=

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
 
K

Keith Thompson

Sönke Tesch said:
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.
 
?

=?ISO-8859-15?Q?S=F6nke_Tesch?=

Keith Thompson wrote:

: > 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
 
P

Peter Slootweg

Sönke Tesch said:
Keith Thompson wrote:

: > 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
 
G

Glen Herrmannsfeldt

Sönke Tesch said:
Keith Thompson wrote:

: > 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
 
?

=?ISO-8859-1?Q?S=F6nke_Tesch?=

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
 

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,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top