I have made a function:
//Returns the total color value
char fg_bg(char fore, char back); //THIS LINE CAUSES AN ERROR
char fg_bg(char fore, char back)
{
char total;
total=(16*back)+fore;
return total;
};
When I then try to:
char color = 0;
color = fg_bg(0x0f, 0x00) // don't care about these hex arguments
the compiler says:
warning: implicit declaration of function ?fg_bg?
So, What IS the problem??? I'd say that the downer code was right, right?
A lot of Errors, owned by my function fg_bg()
Re:A lot of Errors, owned by my function fg_bg()
may be you should use
for declaration!
Code: Select all
char fg_bg(char, char);
Re:A lot of Errors, owned by my function fg_bg()
Is that function declared in another file? The warning probably means it was used before it was declared.
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:A lot of Errors, owned by my function fg_bg()
proper code design would be
Including "stuff.h" in "stuff.c" allows the compiler to check the implementation matches the declaration, and including "stuff.h" in "other.c" allows the compiler to know how "stuff" can be invoked.
Code: Select all
// --- stuff.h
// announce to anyone what 'stuff' offers
char fg_bg(char blah);
Code: Select all
// --- stuff.c
// do stuff
#include "stuff.h"
char fg_bg(char blah)
{
...
}
Code: Select all
// --- other.c
#include "stuff.h"
int other()
{
char x=fg_bg('b');
}