i've some old code from 1999. They have implemented their own loadavg
functions using static in X.c file.
Now i don't want to change the name of loadavg custom functions in
code to loadavg_custom.
But this loadavg is a function defined in stdlib.h. I need other
functions from stdlib.h , so i can't remove the declaration
#include<stdlib.h>
Is there anyway of saying the loadavg in stdlib.h to hide itself ? i
tried doing undef loadavg just after the declaration but it doesn't
work .
It is extremely unlikely that any function is defined in a header.
More likely the function prototype is declared in the header. Unless
you intend to call some of the loadavg functions, the presence of the
declarations in the header should be harmless. If you are rewriting
some of the functions, as long as the signature (return type and
argument types) is the same, the declarations would still be valid.
You need to tell us why the declarations are causing you problems.
stdlib.h is a standard header. loadavg is not a standard library
function. It should not be declared in stdlib.h. If it is, your
compiler should have an option to process only the standard features
of the standard headers. If not, your compiler is not compliant (or
cannot be invoked in a compliant mode) and you will need to raise the
question in a newsgroup that deals with your compiler rather than this
one that deals with the language.
It is possible that "they" (the ones who implemented this back in
1999) modified stdlib.h to include the declaration for loadavg. In
that case, it is permissible to go back in time and terminate them
before they perform this abomination.
One possible method of dealing with such a poor design philosophy
would be:
Scan stdlib.h and identify all the unwanted tokens related to
loadavg.
Build yourself new header (undo_loadavg.h). For each token
identified above, add a #define of the form
#define this_token ____get_rid_of_this_token___
Build yourself a second header (undef_loadavg.h). For each of
the tokens defined out of existence above, add a #undef of the form
#undef this_token
In your code, surround the reference to stdlib.h with
references to the new headers, as in
#include "undo_loadavg.h"
#include <stdlib.h>
#include "undef_loadavg.h"
Now you can add you own loadavg.h header with the declarations
you want.