getting copilation error with gcc 3.4.2

A

Ashay

Hi,
I am getting compilation error "error: parse error before
"__extension__"" for following line of 'C' code:

extern char *strchr(const char *s, int c);
("I had to put this line for some other reasons")

I am using gcc 3.4.2. And, this error is coming only with '-O' option.
With '-g', it is compiling.

Can somebody please help me out.

--Thanks and Regards,
saurabh
 
A

Ashay

Hi,
Sorry, I forgot to mention that I am using following Linux machine:
Linux machinename 2.4.7-10 #1 Thu Sep 6 17:27:27 EDT 2001 i686 unknown
cat /etc/redhat-release
Red Hat Linux release 7.2 (Enigma)

--Thanks,
saurabh
 
E

Eric Sosman

Ashay said:
Hi,
I am getting compilation error "error: parse error before
"__extension__"" for following line of 'C' code:

extern char *strchr(const char *s, int c);
("I had to put this line for some other reasons")

I am using gcc 3.4.2. And, this error is coming only with '-O' option.
With '-g', it is compiling.

Can somebody please help me out.

You have probably #include'd <string.h> in the source,
either directly or indirectly. Once you have done so, you
must not attempt to re-declare the names that <string.h> has
already declared for you. Three possible fixes:

- (poor) Write `extern char *(strchr)( ...etc... );'

- (better) Delete the offending declaration altogether.

- (best) Delete the declaration *and* insert an explicit
#include <string.h> if it's not already there (some
other #include file may pull in <string.h> on your
behalf, but that might change someday -- and if you
#include it explicitly, you'll guard against the
breakage that "someday" might otherwise cause).
 
K

Keith Thompson

Ashay said:
I am getting compilation error "error: parse error before
"__extension__"" for following line of 'C' code:

extern char *strchr(const char *s, int c);
("I had to put this line for some other reasons")

I am using gcc 3.4.2. And, this error is coming only with '-O' option.
With '-g', it is compiling.

Can somebody please help me out.

I presume the ("I had to put this line for some other reasons") is
your comments, and doesn't appear in the source.

Probably strchr is defined as a function-like macro whose definition
uses some non-standard extension called "__extension__".

The way to get the declaration for strchr() is "#include <string.h>".
Why do you need to declare it yourself?
 
A

Ashay

Thanks a lot!!
I saw the preprocessed file and could see the issue. But, Is this
function a macro only in optimized mode and not in '-g' build. Because,
I saw different preprocessed outputs in both the cases.
Actually, somebody in group had put this extern declaration, because he
was not getting incorrect return type("int") for this function, even
after including <string.h>. But, i saw there are many other files
included after this, so some other header file must be redefining
'strchr' which was evetually causing crashes on 64 bit machines,
because of the size diff in 'char*' and 'int'.
But, I think I will be able to solve this issue now.

--Thanks and Best Regards,
saurabh
 

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
474,159
Messages
2,570,881
Members
47,418
Latest member
NoellaXku

Latest Threads

Top