Hi
I want to create a library (.lib) for such a function:
#define baud 19200 #define fpclk 12000000 void setbaud (void);
as a header file (set.h) and
void setbaud (void){ unsigned short int a=(fpclk/16/baud); . . . }
as a .c file (set.c).
compiler gives me a .lib file format and I've add it to my UVproject
and every thing is OK but when I try to write a new #define for baud and fpclk, compiler can compile without any error or warning but every thing is fixed same as those definitions which are mentioned in library(here they're always 19200 and 12000000).
if I remove them in library I'll get an error.
how can I set my library to get such information from outside of library. (Rl-ARM is in this way without any kind of problem)
thanks in advance
Time for you to study C.
Time to you to figure out difference between preprocessing, compile time and run time.
How the xx do you think you can build a function and then later change the preprocessor symbols and have the already compiled code to suddenly and magically recompile itself to behave completely differently?
Runtime makes use of parameters or global variables. A #define is not a variable, so it is not processed during runtime but represents input to the compiler during the compilation stage.
You really should get a good book on the C language.
I wrote an example to explain my problem
I'm not perfect but I know how to write C, but I couldn't find a good way to explain my problem
I know, this is not possible to change a #define in another place or having duplicated definition.
I have some definitions (maybe I should say: constants) and I need to change them outside of library to change the behavior of my library. is it possible or not? if yes, how?
if it's not possible to do such a thing except define them outside of lib same as below:
void setbaud (void);
as a header file in library
void setbaud (unsigned long fpclk,unsigned long baud){ unsigned short int a=(unsigned short int)(fpclk/16/baud); . . . }
as a .c file in library
and in my project I do such a thing:
#define baud 19200 #define fpclk 12000000 void setbaud (unsigned long fpclk,unsigned long baud);
as a header file of my main project and
setbaud (fpclk,baud );
as a .c code
but it's not optimized for me because I don't have enough SRAM space(to use them for local variables and stack).
if anybody has a simple question about fundamental matters, it doesn't mean he or she is stupid, his or her question is foolish and silly question.
if you are perfect, instead of quarreling, you can finish the topic with your direct answer
if you wanna say nonsense words, please say nothing.
hi fellow gurus,,,, we have the problem too,,,,,, and prof needs the code tomorrow lecture. when you have the answer post it here to share with all,,,, only answer or good work accepted...... harash
View all questions in Keil forum