public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/4681] New: declaring strcmp() as an extern function with inclusion of string.h is causing compilation error
@ 2007-06-21 9:26 suma dot sharma at kpitcummins dot com
2007-06-21 9:37 ` [Bug libc/4681] " jakub at redhat dot com
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: suma dot sharma at kpitcummins dot com @ 2007-06-21 9:26 UTC (permalink / raw)
To: glibc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2996 bytes --]
Hi,
I have successfully built SH4-Linux toolchain based on
(binutils-2.17, gcc-4.2-20061205, glibc-2.5) for Renesas SH target.
I am facing problems while compiling the following testcase-
------------------------------------------------------------------
TESTCASE
#include<string.h>
#include<stdio.h>
extern int strcmp(const char *,const char *);
int main()
{
char s1[3];
char s2[3];
strcpy(s1,"12");
strcpy(s2,"2");
printf("\n\t %d",strcmp(s1,s2));
return 0;
}
-------------------------------------------------------------------------
PROBLEM
The above testcase gets compiled with '-O0' optimization successfully----
/sh4-linux-gcc testcase.c o a.out O0
but on compilation with '-O2' optimization option------
/sh4-linux-gcc testcase.c o a.out O2
it gives the following
error:-
testcase.c:4: error: expected identifier or ( before __extension__
testcase.c:4: error: expected identifier or ( before ) token
OBSERVATIONS
1. In the above testcase, declaring strcmp() as an extern function with
inclusion of string.h is causing the above mentioned compilation error. But
on the other hand, if either of the two scenarios is used i.e. either
string.h is included or strcmp() is declared as an extern function only,
then it compiles successfully with O2 option.
2. This problem has been observed with
sh-linux toolchain (gcc-4.2)
i686-pc-linux toolchain (gcc-4.1.1, Fedora Core 6)
i686-pc-linux toolchain (gcc-4.2.0)
Any help on this will be appreciated.
Regards,
Suma Sharma
KPIT Cummins Infosystems Ltd,
Pune (INDIA)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Free download of GNU based SH-Linux toolchains for Renesas' SH
Series.
The following site also offers free technical support to its
users.
Visit http://www.kpitgnutools.com for details.
Latest versions of KPIT GNU SH-Linux tools were released on April 5,
2007.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
Summary: declaring strcmp() as an extern function with
inclusion of string.h is causing compilation error
Product: glibc
Version: unspecified
Status: NEW
Severity: normal
Priority: P3
Component: libc
AssignedTo: drepper at redhat dot com
ReportedBy: suma dot sharma at kpitcummins dot com
CC: glibc-bugs at sources dot redhat dot com,suma dot sharma
at kpitcummins dot com
GCC build triplet: i686-pc-linux
GCC host triplet: sh4-unknown-linux
GCC target triplet: sh4-unknown-linux
http://sourceware.org/bugzilla/show_bug.cgi?id=4681
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug libc/4681] declaring strcmp() as an extern function with inclusion of string.h is causing compilation error
2007-06-21 9:26 [Bug libc/4681] New: declaring strcmp() as an extern function with inclusion of string.h is causing compilation error suma dot sharma at kpitcummins dot com
@ 2007-06-21 9:37 ` jakub at redhat dot com
2007-06-21 10:59 ` suma dot sharma at kpitcummins dot com
2007-07-02 15:56 ` jakub at redhat dot com
2 siblings, 0 replies; 4+ messages in thread
From: jakub at redhat dot com @ 2007-06-21 9:37 UTC (permalink / raw)
To: glibc-bugs
------- Additional Comments From jakub at redhat dot com 2007-06-21 09:37 -------
That's a bug in your testcase, you shouldn't declare functions defined in
system headers yourself, just include the appropriate header.
POSIX and ISO C allow these to be defined as macros.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |INVALID
http://sourceware.org/bugzilla/show_bug.cgi?id=4681
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug libc/4681] declaring strcmp() as an extern function with inclusion of string.h is causing compilation error
2007-06-21 9:26 [Bug libc/4681] New: declaring strcmp() as an extern function with inclusion of string.h is causing compilation error suma dot sharma at kpitcummins dot com
2007-06-21 9:37 ` [Bug libc/4681] " jakub at redhat dot com
@ 2007-06-21 10:59 ` suma dot sharma at kpitcummins dot com
2007-07-02 15:56 ` jakub at redhat dot com
2 siblings, 0 replies; 4+ messages in thread
From: suma dot sharma at kpitcummins dot com @ 2007-06-21 10:59 UTC (permalink / raw)
To: glibc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1456 bytes --]
------- Additional Comments From suma dot sharma at kpitcummins dot com 2007-06-21 10:59 -------
I have observed that, if strcpy is used in the exact same scenario
as strcmp above, i.e. if strcpy is declared as an external function
with string.h also included, then the Compilation error as reported
for strcmp earlier is not observed.
strcpy as well as strcmp are defined as macros. Then why such variance?
Kindly provide some suggestions.
Regards,
Suma Sharma
KPIT Cummins Infosystems Ltd,
Pune (INDIA)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Free download of GNU based SH-Linux toolchains for Renesas' SH
Series.
The following site also offers free technical support to its
users.
Visit http://www.kpitgnutools.com for details.
Latest versions of KPIT GNU SH-Linux tools were released on April 5,
2007.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |REOPENED
Resolution|INVALID |
http://sourceware.org/bugzilla/show_bug.cgi?id=4681
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug libc/4681] declaring strcmp() as an extern function with inclusion of string.h is causing compilation error
2007-06-21 9:26 [Bug libc/4681] New: declaring strcmp() as an extern function with inclusion of string.h is causing compilation error suma dot sharma at kpitcummins dot com
2007-06-21 9:37 ` [Bug libc/4681] " jakub at redhat dot com
2007-06-21 10:59 ` suma dot sharma at kpitcummins dot com
@ 2007-07-02 15:56 ` jakub at redhat dot com
2 siblings, 0 replies; 4+ messages in thread
From: jakub at redhat dot com @ 2007-07-02 15:56 UTC (permalink / raw)
To: glibc-bugs
------- Additional Comments From jakub at redhat dot com 2007-07-02 15:56 -------
That's irrelevant.
The functions may but don't have to be implemented as macros and even the macros
may or may not have definitions which cause compile errors when you incorrectly
try to provide prototype after including string.h.
The standard clearly says what you are doing is invalid. See e.g. ISO C99,
7.1.4/1 or
http://www.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_02.html#tag_02_02_02
(in the latter particularly:
"Applications shall not declare or define identifiers with the same name as an
identifier reserved in the same context.").
--
What |Removed |Added
----------------------------------------------------------------------------
Status|REOPENED |RESOLVED
Resolution| |INVALID
http://sourceware.org/bugzilla/show_bug.cgi?id=4681
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-07-02 15:56 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-21 9:26 [Bug libc/4681] New: declaring strcmp() as an extern function with inclusion of string.h is causing compilation error suma dot sharma at kpitcummins dot com
2007-06-21 9:37 ` [Bug libc/4681] " jakub at redhat dot com
2007-06-21 10:59 ` suma dot sharma at kpitcummins dot com
2007-07-02 15:56 ` jakub at redhat dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).