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
Hi all
I was thinking I myself have such a problem.
you said:
If they change, then they aren't constant - are they?!
these definitions are same as constant that developer can change them before compiling
when I was surfing in keil setup path I found it that rl-arm have such a definitions for its library and in rtx_lib.c implement in this way:
for example in rtx_config.c we have:
#ifndef OS_TASKCNT #define OS_TAKCNT 5 #endif
and in rtx_lib.c we have:
U16 const OS_maxtaskrun=OS_TASKCNT;
here I try to make a library same as it:
in library:
extern int const baud; extern unsigned long const fpclk; void set(void){ unsigned short int a=((fpclk/16)/baud); }
and in main project:
#define baud_rate 19200 #define fpclock 12000000 int const baud=baud_rate; unsigned long const fpclk=fpclock;
as a header file and
int main(void){ set(); }
and it works properly but, I think #define is other think for C development
any idea?
only answer or good work accepted
It seems that quite some people here are developing an acute form of a Saddam Hussain/Muamar Ghadaffi/Osama Bin Laden etc. complex. You know, the rule of thumb is that we don't talk to terrorists...
@harash amakaar,
Ah, "fellow gurus"? You're not even close to that. Right now you're only a slum-bound, cheating scumbag (sorry for that) student/thief/liar. Shame on you!
"these definitions are same as constant that developer can change them before compiling"
So you still haven't grasped what Per pointed out about libraries?
Libraries are compiled code - so you can't change the constants definitions!
I've written a lot of samples here. I want to set for example baudrate as an optional value for user. so I need to change some constants
about rl-arm rtx confige has the same thing about volume of stack per task,num of tasks, and etc
are they fixed in library, and there is no way to change them?
I think the best way is that one which I said, but if anybody knows another way, please mention it.
Then provide a function that the user calls to do that at run time; eg,
void set_baudrate( int baudrate );
This will probably require some other supporting functions (or additional parameters); eg, to tell the library the available clock frequency...
Remember that a project can let a library function make use of a global variable that get its value in the application code.
And library functions can of course take parameters.
It's just that they can't make use of constants that are defined first at the compilation of the application code.
For something to happen at runtime, you need to send the value of the constant to the library function, or you need to store the value of the constant in a variable (potentially read-only) that the library function knows the existence and type of.