I use uVision2 of Windows version. How to create my own library and how to use it when linking?
Use the archiver that comes with your toolset. Then add the library to your link line (just like you do with .obj's). - Mark
Thanks! But I still don't know how to directly use it in Windows environment.Possible?
But I still don't know how to directly use it in Windows environment. Possible? Not exactly, you could call it from a batch file which the Windows environment could call for you. Best just to go to the trusty old command line and type:
C:\Keil\C51\BIN>lib51 ? LIB51 LIBRARY MANAGER V4.12 COPYRIGHT KEIL ELEKTRONIK GmbH 1987 - 1999 Add {file[(module[,...])]} [,...] TO library_file Create library_file Delete library_file(module[,...]) Exit eXtract library_file(module) TO file Help List library_file [TO file] [PUBLICS] Replace {file[(module[,...])]} [,...] IN library_file Transfer {file[(module[,...])]} [,...] TO library_file
Nothing can be simpler. You just add your .lib file to your project. You needn't make any #include or anything of the kind. And in your .c file you can use your library functions. Michael.
You needn't make any #include or anything of the kind. Well, of course your 'C' file(s) will need something to declare those functions - so either you'll have to manually enter the prototypes, or make a header and #include it.
Hi, Andrew, It seems to me you had not tested it before you made your remark. Keil C is not real C, it is something rather special. It works as I said, even without prototype - you'll only get a warning. Michael.
Actually, that is real 'C' Unless advised otherwise (eg, by a function prototype) 'C' assumes that all functions return int and take no parameters [1]. Therefore you can call library functions without specifying a prototype provided that they take no parameters and the return value is either not used, or is assignment-compatible with 'int'. You must provide a prototype if you want your library function to take any parameters, or you'll get error C267, "requires ANSI-style prototype" But it's always good practice to provide function prototypes, as this gives the compiler the chance to warn you of type mismatches. [1] kernighan & Ritchie "The C Programming Language, 2/ed" Prentice-Hall, 1988.
Probably you are right - I never use functions that take or return any parameter - it's too slow. Michael.
Keil C51 is ANSI C with extensions. The C standard does not require implementations to require prototypes. - Mark
Too slow? What are you talking about? Show me the assembler to back that statement up. It is extremely bad style and unsafe to use globals to pass information between functions. Besides if your functions are void func(void) and you don't prototype them you should get a warning since C expects you return int. - Mark
Quite right! It's also unsafe & bad style to have a build in which warnings are normal. One day there will be one extra warning, and that one will indicate a real problem in your code. If your build is normally littered with warnings, that'd be easy to miss and the problem could get through into products and jump up and bite in some obscure fashion at some inopportune moment. But if your build is normally "clean," a new warninng would stand out like a sore thumb and you could easily catch it before it bites. Been there...
I am very pleased to know that the final judgement is delivered - which style is good and which is bad. Far from trying to alter it I would like to remark that I personally like the style that is more profitable - and do not impose my opinion. Michael.
Any statement made by me is my opinion based upon 13 years of experience. I by no means meant it as some "final judgement" as you say. Sorry if you took it that way. Regards. - Mark