473,799 Members | 3,147 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

what is the meaning of "implicit declaration of function `malloc'"?

the following is my programming code and compile message
why the warning message arise, have i done somethings wrong?
#include<stdio. h>
typedef struct card{

int abc;
}card;

int main(){
card *d;
d = (card*) malloc(sizeof(c ard));
return 0;

}

the compile message :

--------------------Configuration: test - Debug--------------------
Compiling source file(s)...
test.c
test.c: In function `main':
test.c:11: warning: implicit declaration of function `malloc'
Linking...

test.exe - 0 error(s), 1 warning(s)

thanks!
Nov 15 '05 #1
2 34588
nick wrote:

the following is my programming code and compile message
why the warning message arise, have i done somethings wrong?

#include<stdio. h>
You neglected to write this here:

#include <stdlib.h>
d = (card*) malloc(sizeof(c ard)); test.c:11: warning: implicit declaration of function `malloc'


The declaration for malloc, is in stdlib.h.
Without the declaration in scope,
C89 assumes malloc returns type int.

With the declaration in scope,
the compiler knows that malloc returns type pointer to void.
The (card*) cast that you used, suppressed the warning
that you would have gotten for assigning an int value
to a pointer type.

Add
#include <stdlib.h>
and lose the cast.

--
pete
Nov 15 '05 #2
nick wrote:
the following is my programming code and compile message
why the warning message arise, have i done somethings wrong?
The error message test.c:11: warning: implicit declaration of function `malloc' tells you: you have failed to have a declaration for the function
'malloc' in scope. This is easily fixed with
#include <stdlib.h>
No doubt you failure to #include <stdlib.h> accounts for the silly cast
on the return value from malloc()

#include<stdio. h>
typedef struct card{
int abc;
}card;

int main(){
card *d;
d = (card*) malloc(sizeof(c ard));
There is no excuse for the cast. If you put it in to stop complaints
from the compiler, you treated the symptom rather than the problem.
The normal form of this call is
d = malloc(sizeof *d);
And you should check the returned value.
return 0;
}


These and similary issues are covered in the FAQ. Before posting to a
newsgroup, check its FAQ and follow the newsgroup for several weeks (The
google.groups.c om archive makes this 'following for several weeks'
something that you can do in a much shorter time). Following these two
simple rules will keep you from asking old, tired questions that have
been answered repeatedly. Consider that your question has been asked
hundreds of times. There are two results: very few people will bother
to answer yet again the same question to which you *should* have already
found the answer by checking the FAQ, and people become angry that you
presume that we should waste our time answering a question that you
won't bother putting in any effort to find the answer on your own.
Nov 15 '05 #3

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

Similar topics

2
2929
by: Li Daobing | last post by:
Hello, Does anyone know what's the meaning of Dutch in "The Zen of Python"? Thanks in advance Li Daobing The Zen of Python, by Tim Peters
2
2476
by: Andy | last post by:
Hi, What is implicit extern "C" declaration in C++? Can anybody give me an example? Thanks a lot! Andy
3
2961
by: Generic Usenet Account | last post by:
This is a two-part question. (1) I have implemented a "Datastructure Registry" template class. I am getting no compiler warnings with older compilers, but newer compilers are generating the following error messages: warning: implicit typename is deprecated, please see the documentation for details Can someone kindly suggest how to get rid of these warnings? The source code follows.
3
2271
by: Juha Nieminen | last post by:
Consider this code: void foo(int& i) { i += 10; } int main() { int a = 1;
14
2366
by: Chen Shusheng | last post by:
CSS white here: Simply strange, I found "define" can not work with "malloc". Together my complier will say "parse error". Could anyone tell me why? ------------------------- #define MAX 10000 ....... int main(void){ .....
5
10881
Rabbit
by: Rabbit | last post by:
I've #included <stdlib.h> at the beginning of the file. Weird thing is this compiled fine before, then I changed the code of one of the functions, which should, as far as I know, have nothing to do with this piece: buffer = (char*)malloc(100*sizeof(char)); And now I'm getting that error. So I figured I must have missed something in the tutorial so when I couldn't find anything by sight, I copied all the source files from the tutorial and...
2
1990
by: Jolie Chen | last post by:
I am learning template programming now, and I wrote the following code #include <iostream> #include "Queue.h" using namespace std; template <typename Tclass QueueItem { public: QueueItem(T item):value(item),next(0){}
36
3821
by: James Harris | last post by:
Initial issue: read in an arbitrary-length piece of text. Perceived issue: handle variable-length data The code below is a suggestion for implementing a variable length buffer that could be used to read text or handle arrays of arbitrary length. I don't have the expertise in C of many folks here so I feel like I'm offering a small furry animal for sacrifice to a big armour plated one... but will offer it anyway. Please do suggest...
11
2525
by: markryde | last post by:
Hello, Followed here is a simplified code example of something which I try to implement; in essence , I want to assign a value to a return value of a method is C. I know, of course, that in this example I can get this by newskb->iph = iphdr (this also appears in a commented line in the example below) ; but I want to achieve the same where the left side is : ip_hdr(newskb). Alas, if I try this , I get a compilation error about line 25....
0
9688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9546
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,...
0
10031
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
9079
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
7571
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
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5593
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4146
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
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.