Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > How to use maloc with strcut

Reply
Thread Tools

How to use maloc with strcut

 
 
Mateusz_madi
Guest
Posts: n/a
 
      05-13-2010
I have program:
--------------
#include<stdio.h>
struct s{
int x;
struct s* nxt;
};

void f(struct s* pt)
{
malloc(sizeof(struct s));
}
.....
Why i get warrning when i'am trying to compile it sth like:
Incompatible implicit declaration of build-in function 'malloc'
??







 
Reply With Quote
 
 
 
 
Seebs
Guest
Posts: n/a
 
      05-13-2010
On 2010-05-13, Mateusz_madi <(E-Mail Removed)> wrote:
> I have program:
> --------------
> #include<stdio.h>
> struct s{
> int x;
> struct s* nxt;
> };
>
> void f(struct s* pt)
> {
> malloc(sizeof(struct s));
> }
> ....
> Why i get warrning when i'am trying to compile it sth like:
> Incompatible implicit declaration of build-in function 'malloc'
> ??


This has nothing to do with the struct, and everything to do with the fact
that you called malloc(), but you never included <stdlib.h>, so it hasn't
been declared. The compiler knows about malloc, though.

In C89, if you used a function without a declaration, it was assumed to return
int. malloc() doesn't return int, and the compiler is warning you that
this probably means something has gone wrong. Which it has.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
 
Reply With Quote
 
 
 
 
Mateusz_madi
Guest
Posts: n/a
 
      05-13-2010
On 13 Maj, 19:39, Seebs <(E-Mail Removed)> wrote:
> On 2010-05-13, Mateusz_madi <(E-Mail Removed)> wrote:
>
>
>
> > I have program:
> > --------------
> > #include<stdio.h>
> > struct s{
> > int x;
> > struct s* nxt;
> > };

>
> > void f(struct s* pt)
> > {
> > *malloc(sizeof(struct s));
> > }
> > ....
> > Why i get warrning when i'am trying to compile it sth like:
> > Incompatible implicit declaration of build-in function 'malloc'
> > ??

>
> This has nothing to do with the struct, and everything to do with the fact
> that you called malloc(), but you never included <stdlib.h>, so it hasn't
> been declared. *The compiler knows about malloc, though.
>
> In C89, if you used a function without a declaration, it was assumed to return
> int. *malloc() doesn't return int, and the compiler is warning you that
> this probably means something has gone wrong. *Which it has.
>
> -s
> --
> Copyright 2010, all wrongs reversed. *Peter Seebach / (E-Mail Removed)://www.seebs.net/log/<-- lawsuits, religion, and funny pictureshttp://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!


Thank's seebs
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Strcut padding? webinfinite@gmail.com C++ 1 02-27-2008 03:44 AM
Re: Strcut padding? diligent.snail@gmail.com C++ 0 02-23-2008 02:22 AM
where to use CPLD & where to use FPGA? kulkarku@math.net VHDL 6 03-06-2006 07:27 AM
Cannot use the profile "default" because it is in use, not. please.post@yur.re.ply Firefox 1 07-04-2004 03:41 AM



Advertisments