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

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
OSMAN

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

Post 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?
codemastersnake

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

Post by codemastersnake »

may be you should use

Code: Select all

char fg_bg(char, char);
for declaration!
AR

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

Post by AR »

Is that function declared in another file? The warning probably means it was used before it was declared.
User avatar
Pype.Clicker
Member
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()

Post 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.
Post Reply