Page 1 of 1

A lot of Errors, owned by my function fg_bg()

Posted: Wed Aug 17, 2005 2:16 pm
by OSMAN
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?

Re:A lot of Errors, owned by my function fg_bg()

Posted: Wed Aug 17, 2005 2:34 pm
by codemastersnake
may be you should use

Code: Select all

char fg_bg(char, char);
for declaration!

Re:A lot of Errors, owned by my function fg_bg()

Posted: Thu Aug 18, 2005 12:05 am
by AR
Is that function declared in another file? The warning probably means it was used before it was declared.

Re:A lot of Errors, owned by my function fg_bg()

Posted: Thu Aug 18, 2005 5:13 am
by Pype.Clicker
proper code design would be

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');
}
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.