473,738 Members | 5,084 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Warnings with gcc

Hello,
I get a warning when I compile:
#include <string.h>

int main (int argc, char ** argv)
{
char * s;
s = strdup("a string");
return 0;
}

with gcc (GCC) 3.3.5 (Debian 1:3.3.5-8ubuntu2) :

$ gcc -Wall -ansi warning.c
warning.c: In function `main':
warning.c:7: warning: implicit declaration of function `strdup'
warning.c:7: warning: assignment makes pointer from integer without a
cast

Does anybody knows how can I supress this warning ?

if I put a cast : s = (char *) strdup("a string");
I get another warning message:
warning.c:7: warning: implicit declaration of function `strdup'

I do not understand why this happens because strdup is declared in
string.h

Thanks,

Thibault Langlois

Nov 23 '05 #1
34 3630

<th************ ***@di.fc.ul.pt > wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.com.. .
Hello,
I get a warning when I compile:
#include <string.h>

int main (int argc, char ** argv)
{
char * s;
s = strdup("a string");
return 0;
}

with gcc (GCC) 3.3.5 (Debian 1:3.3.5-8ubuntu2) :

$ gcc -Wall -ansi warning.c
warning.c: In function `main':
warning.c:7: warning: implicit declaration of function `strdup'
warning.c:7: warning: assignment makes pointer from integer without a
cast

Does anybody knows how can I supress this warning ?

if I put a cast : s = (char *) strdup("a string");
I get another warning message:
warning.c:7: warning: implicit declaration of function `strdup'

I do not understand why this happens because strdup is declared in
string.h


Well, it can't be can it - unless the compiler's wrong?

Have you confirmed that it's in [your] string.h?

Does your preprocessed output contain it?

Does it link?

rayw
Nov 23 '05 #2
th************* **@di.fc.ul.pt wrote:
I do not understand why this happens because strdup is declared in
string.h


strdup is not in string.h

news:gnu.gcc

http://www.ungerhu.com/jxh/clc.welcome.txt

--
pete
Nov 23 '05 #3
"th************ ***@di.fc.ul.pt " <th************ ***@di.fc.ul.pt > wrote:
I get a warning when I compile:
#include <string.h>

int main (int argc, char ** argv)
{
char * s;
s = strdup("a string");
return 0;
} warning.c:7: warning: implicit declaration of function `strdup'

I do not understand why this happens because strdup is declared in
string.h


strdup() is not ISO C, and should therefore _not_ be declared in
<string.h> in a conforming implementation. Looks like gcc with -ansi is
conforming in this respect (as in most, perhaps all, others).

Richard
Nov 23 '05 #4
th************* **@di.fc.ul.pt wrote:
Hello,
I get a warning when I compile:
#include <string.h>

int main (int argc, char ** argv)
this is better than int main () or void main (void) which we see too
often around here, but since you are not using either of these
variables, why not just int main (void)?
{
char * s;
s = strdup("a string");
strdup is not a Standard C function, it is a BSD extension. You
specified the -ansi option when you tried to compile this telling the
compiler you want to compile as a strictly conforming program. This
option defines the macro __STRICT_ANSI__ which will keep the prototype
for strdup from being visible from string.h. You can either remove the
-ansi switch, or place the following define before your include
directive:
#define _GNU_SOURCE
return 0;
}

with gcc (GCC) 3.3.5 (Debian 1:3.3.5-8ubuntu2) :

$ gcc -Wall -ansi warning.c
warning.c: In function `main':
warning.c:7: warning: implicit declaration of function `strdup'
The prototype for strdup is not in scope, hence the diagnostic, see
above.
warning.c:7: warning: assignment makes pointer from integer without a
cast
Since the prototype for strdup is not in scope, the compiler assumes it
returns an int which you are storing into a pointer without a cast,
this is required to produce a diagnostic.
Does anybody knows how can I supress this warning ?
The -w switch turns off all warnings but this justs hides the problem,
fix the issue instead.
if I put a cast : s = (char *) strdup("a string");
I get another warning message:
warning.c:7: warning: implicit declaration of function `strdup'


Since you cast the result of strdup, which the compiler thinks is an
int, to a char * a diagnostic is not required. You still have the
issue of strdup not being declared. If you are using a cast to supress
a compiler diagnostic, this is a good clue you are doing something
wrong.

Robert Gamble

Nov 23 '05 #5

<th************ ***@di.fc.ul.pt > wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.com.. .
Hello,
I get a warning when I compile:
#include <string.h>

int main (int argc, char ** argv)
{
char * s;
s = strdup("a string");
return 0;
}

with gcc (GCC) 3.3.5 (Debian 1:3.3.5-8ubuntu2) :

$ gcc -Wall -ansi warning.c
warning.c: In function `main':
warning.c:7: warning: implicit declaration of function `strdup'
warning.c:7: warning: assignment makes pointer from integer without a
cast

Does anybody knows how can I supress this warning ?

if I put a cast : s = (char *) strdup("a string");
I get another warning message:
warning.c:7: warning: implicit declaration of function `strdup'

I do not understand why this happens because strdup is declared in
string.h

Thanks,

Thibault Langlois


drop the "-ansi" strdup is a non-ANSI extension (at least according to gcc).

barry
Nov 23 '05 #6
Barry wrote:
<th************ ***@di.fc.ul.pt > wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.com.. .
I get a warning when I compile:
#include <string.h>

int main (int argc, char ** argv)
{
char * s;
s = strdup("a string");
return 0;
}

with gcc (GCC) 3.3.5 (Debian 1:3.3.5-8ubuntu2) :

$ gcc -Wall -ansi warning.c
warning.c: In function `main':
warning.c:7 : warning: implicit declaration of function `strdup'
<snip>
drop the "-ansi" strdup is a non-ANSI extension (at least according to gcc).

That's not quite it. gcc would in fact be allowed to provide strdup()
even in ANSI mode, but it chooses not to, presumably to help people
catch conformance errors (which is -ansi's primary purpose).

(To be even more precise, it actually depends on the standard library
implementation used with gcc.)

S.
Nov 23 '05 #7

"Skarmander " <in*****@dontma ilme.com> wrote in message
news:43******** *************** @news.xs4all.nl ...
Barry wrote:
<th************ ***@di.fc.ul.pt > wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.com.. .
I get a warning when I compile:
#include <string.h>

int main (int argc, char ** argv)
{
char * s;
s = strdup("a string");
return 0;
}

with gcc (GCC) 3.3.5 (Debian 1:3.3.5-8ubuntu2) :

$ gcc -Wall -ansi warning.c
warning.c: In function `main':
warning.c:7 : warning: implicit declaration of function `strdup' <snip>

drop the "-ansi" strdup is a non-ANSI extension (at least according to

gcc).

That's not quite it. gcc would in fact be allowed to provide strdup()
even in ANSI mode, but it chooses not to, presumably to help people
catch conformance errors (which is -ansi's primary purpose).

(To be even more precise, it actually depends on the standard library
implementation used with gcc.)

S.


Thanks for the correction. My post was based solely on the comments in the
gcc
header files.

barry
Nov 23 '05 #8
pete wrote:
th************* **@di.fc.ul.pt wrote:

I do not understand why this happens because strdup is declared in
string.h

strdup is not in string.h

news:gnu.gcc

http://www.ungerhu.com/jxh/clc.welcome.txt

strdup is in string.h in my linux system with
gcc version 2.96 20000731 (Mandrake Linux 8.2 2.96-0.76mdk)

jacob
Nov 23 '05 #9
jacob navia wrote:
pete wrote:
th************* **@di.fc.ul.pt wrote:

I do not understand why this happens because strdup is declared in
string.h


strdup is not in string.h

news:gnu.gcc

http://www.ungerhu.com/jxh/clc.welcome.txt

strdup is in string.h in my linux system with
gcc version 2.96 20000731 (Mandrake Linux 8.2 2.96-0.76mdk)

strdup() is *not necessarily* in string.h. It's a nonstandard function;
the standard doesn't define it. Implementations are allowed to define
additional functions beginning with "str" in <string.h>, however (and if
<string.h> is included, a program may not define such functions).

S.
Nov 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
2205
by: Kylotan | last post by:
I have the following code: def IntToRandFloat(x): """Given a 32-bit integer, return a float in """ x = int(x) x = int(x << 13) ^ x return (1.0-((x*(x*x*15731+789221)+1376312589)&0x7fffffff)/1073741824.0) Basically it's a function directly copied from a C implementation. Now
12
11030
by: Gary | last post by:
Hi! guys, I have a SQL agent job fails because it gets 10 warnings when it runs a stored procedure. These warnings are trivial and can be ignored. Can I make it ignore these warnings and proceed? I think there is some setting I can do to change the default behavour of an agent job regarding warnings but I just don't know how to do it. Any idea?
3
5786
by: Terry Richards | last post by:
mysql 4.1.9-standard how do i find exactly what the warnings are when i only get Query OK, 1 row affected, 1 warning (0.00 sec) :-)^2
30
2181
by: prasanna | last post by:
i will be very thankful if you sent all the errors and warnings regarding to the language C thank you
22
8312
by: John Fisher | last post by:
void f(int p) { } Many (most?) compilers will report that p is unreferenced here. This may not be a problem as f may have to match some common prototype. Typically pointers to functions are involved. For a long time I have used
2
2085
by: funkyj | last post by:
I've been googling around trying to find the answer to this question but all I've managed to turn up is a 2 year old post of someone else asking the same question (no answer though). http://groups.google.com/group/comp.lang.python/browse_frm/thread/8004c690b8c4db53/81e460a0ee8b03a5?lnk=st&q=python+warnings+echo&rnum=6#81e460a0ee8b03a5 jh> In the following jh> jh> import warnings jh> warnings.warn('change me')
6
1910
by: pete142 | last post by:
When I compile this code: typedef unsigned char BYTE; BYTE * IpString(unsigned int ip) { static BYTE ipString; ipString = (BYTE) 0xff & (ip >24); ipString = (BYTE) 0xff & (ip >16);
3
3191
by: gil | last post by:
Hi, I'm trying to find the best way to work with compiler warnings. I'd like to remove *all* warnings from the code, and playing around with the warning level, I've noticed that compiling with /W3 I get warnings that with /W4 are shown as remarks, e.g.: warning #177: variable "Foo" was declared but never referenced ....is displayed as a "remark #177" with /W4. That doesn't fit the
1
1514
by: billiejoex | last post by:
Hi there, into a module of mine I 'warn' a message if a certain situation occurs: def add_anonymous_user(permissions=('r'): if 'w' in p: import warnings warnings.warn("it's not rencommended assigning 'w' permission to anonymous user.", RuntimeWarning, stacklevel=2)
1
2514
by: Robert Singer | last post by:
Platform: winXP, excel 2003 Python 2.5.2 XLWriter 0.4a3 (http://sourceforge.net/projects/pyxlwriter/) Is anyone here using this very nice package, for writing excel files? I'm using it on python 2.5.2. (although it is made for older version of python) and cannot find a way to get rid of this error (code and errors below). Does anyone know how to avoid it ? I would appreciate all help and
0
8787
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9259
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9208
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6750
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4569
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.