Results 1 to 2 of 2
08-17-2009, 03:03 AM #1
- Join Date
- Aug 2009
Application won't read header file correctly.
Hi, I decided to create a 2 byte fraction type instead of using floats. The type is a struct with two elements, an integer part and a fractional part.
I created a header file with an implementation containing some simple arithmetics. During my (many) tests the compiler reported no errors, however when I decided to use this libriary in another application a got some wierd errors.
Here is the header file (frac.h):
unsigned char in, fr;
extern const UFRAC F_ZERO;
#define UFRAC_SIZE 2
#define UFRAC_MAX 0xff
char f_isless(UFRAC a, UFRAC b);
float f_tofloat(UFRAC a);
UFRAC f_add(UFRAC a, UFRAC b);
UFRAC f_sub(UFRAC a, UFRAC b);
UFRAC f_idiv(UFRAC a, unsigned char i); //fraction divided with an integer
UFRAC f_imult(UFRAC a, unsigned char i);//fraction multiplied with an integer
In "main.c" I include the header file "frac.h" as one would. I can define a variable with UFRAC as type and I can use some functions... but not all. The functions f_idiv and f_imult will run with no problems as long as I don't assign a UFRAC variable to it's return value, so this will run:
... but this:
b=f_imult(a,2) //were b and a are UFRAC:s
will give the error: "In main.c: incompatible types in assignment" even thou f_imult's return type is UFRAC. Also the F_ZERO (defined in "frac.c" and in "frac.h" with external) is not defined in "main.c". However the macros are.
Since my testing application report no errors (implicating that there is nothing wrong with my library) I believe that my "main.c" is where the error is, but I fail to see an error or typo (I will not send the complete file, pretty large).
Can someone please tell me why this won't work or why these errors occur, I would really appriciate it.
A part from "frac.h" I'm also including "stdlib.h" and "glut.h". I'm using Dev-C++'s C-compiler on Windows XP.
08-17-2009, 09:14 AM #2
- Join Date
- Dec 2007