|
From: Per W. <pw...@ia...> - 2002-12-11 09:21:35
|
You may continue to include stdlib.h as normal. Put your atoi() in either your main program, or in a separate source file. Dev-C++ will make sure that the object file containing your atoi will be linked before the standard libraries, i.e. that your version of atoi will be used instead of the implementation in the standard libraries. The reason you want stdlib.h both when implementing and when using your atoi is that it must have exactly the same format as the original implementation, or any calls from within the standard libraries will fail. One other thing - if the original implementation of atoi in the standard libraries was placed in a source file together with a number of other standard functions, you might have to replace these functions too. A library is just a collection of individual object files, and the linker may never perform linking on individual functions or variables. All linking is performed on complete object files. I saw some references in a couple of other mails about using inline or placing the atoi declaration in a different include file etc. No, you don't need to do these steps. The linker thinks it's ok to have the same symbol defined in your object files and in the libraries. It will just pick the object file instead of extracting an implementation from the library file. The only reason for taking extra steps is if you want to be able to call both a new and an old implementation in the same program. In that case you have to do something like: #define atoi my_atoi in an include file, to map all calls to your new atoi. Then in the part of the program where you want to access the original atoi, you have to do: #undef atoi return atoi(x) Note that this concept doesn't work if atoi would already from the beginning be a #define'd symbol. The concept of fooling around with #define is for example used in a number of environments, to replace the memory allocation functions with debug versions that checks heap validity and that you remember to release all memory on program end. /Per W On Tue, 10 Dec 2002, Zachary Uram wrote: > At 03:27 AM 12/10/02, Per Westermark wrote: > >Yes, I can see that your code does try to use the <strlib.h> file, but > >there are no such standard file. Whenever you find that Dev-C++ is missing > >a standard include file, there is a very, very large proability that you > >have either misspelled the include file, or that it isn't such a STANDARD > >include file, but something special installed by some 3rd party tool on a > >machine somewhere. > > > >That's why I wondered if it wasn't <stdlib.h> that should be used instead. > >It might also be the <string.h> file that was intended. > > > ><stdlib.h> contains among other things atoi() implemented in your source. > ><string.h> contans strchr() declaration. > > > Hi Per, > > How can I tell the compiler to use my verson of atoi() and not the one in > the stdlib.h library? > I will try replacing strlib.h with string.h as well. > > Zach > > Zachary Uram > John 3:16 > <>< > > |