473,394 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Implicit declaration of a function?

Hello - I have a .c file that gives me a warning "implicit declaration of function function_name".

However, I have #included the header file that #defines that funciton, so how is it possible to have an implicit declaration??

Thanks!
Jul 17 '08 #1
1 7437
arnaudk
424 256MB
#define is a preprocessor directive, it does not declare nor define functions.

This is how you declare and define a function:
Expand|Select|Wrap|Line Numbers
  1. void myfunction(); // declaration
  2.  
  3. int main()
  4. {
  5. myfunciton(); // use function
  6. return 0;
  7. }
  8.  
  9. void myfunction() { // definition
  10. }
  11.  
If you omit the declaration, then you will probably get a "conflicting types" warning since the compiler declared it for you and may use a different prototype than what you use in your definition. You are allowed to omit the declaration if you put the definition where the declaration is - before any calls to the function.

If you omit the definition you'll get an linker error unless its defined in another .c/.cpp file which you compile at the same time.

If you use #define to "define" your function then you will have unintentionally defined a preprocessor macro not a function and monkeys will fly out your ears.

One more thing: C++ (not C) supports function overloading so if your function is defined to take three arguments for example and you try to call it with two, then the compiler will look for an overloaded version of the function which takes two arguments. When it doesn't find it, it will implicitly declare it.
Jul 17 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Jason | last post by:
Hi, Im running windows xp pro and compiling using dev c++ 4. I have the following situation: #include <iostream> #include <string> using namespace std; int main() {
2
by: nick | last post by:
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;
7
by: Paminu | last post by:
On a gentoo linux system i don't get any warnings when I comlpile this code: #include <stdio.h> typedef struct test { void *content; struct test_ *bob; } test_;
5
by: Christian Christmann | last post by:
Hi, in one file I've a function that is used by another file containing the main function: file1.c: .... void test( int a ) { ... } ....
6
by: Bart Rider | last post by:
I've written a short c-programm using srand48 and drand48. After compiling with gcc - gcc -o foo foo.c -W -Wall -pedantic -ansi - I get the warnings - foo.c: In function `main': foo.c:7:...
6
by: yeah | last post by:
hi I got this error "implicit declaration of function" what it means???
14
by: UNCManiac37 | last post by:
Hi, I'm very new to coding, so this is a newbie question. I'm trying to print out a banner using functions instead of main: int main () { banner1 (); } void banner1 (void) { cout...
5
by: DanielJohnson | last post by:
I call a function which is named as func_name in file /source/folderA/ fileA.c. The actual function definition is in /source/folderB/fileB.c. And I get this error. warning: implicit...
3
by: samdomville | last post by:
hello...upon compilation, i get a warning: "warning: implicit declaration of funciton funciton_name" what, techicallly, is an implicit declaration? how/where would i look to track down the error?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...

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.