Reputation: 117
I have three files.
teacher.c was supplied to me and cannot be changed it in any way and the other two files were coded by me.
teacher.c has the main() function and includes ass3.h.
ass3.c also includes ass3.h. teacher.c calls for functions in ass3.c.
The program works but I need to add another functionality.
I need to add the ability for a user to specify if user wants to use a macro or a function (call it isAvail()). Right now the program works only using the isAvail() function.
How do I go about implementing this? The excerpt for the requirement is:
"Implement isAvail() as a function and a macro expansion(macro) using conditional processing, the user can choose between macro or a function in the compiled code. If IS_AVAIL (the macro name) name is defined the macro should be used, if the IS_AVAIL name is not defined, the function should be used"
Again, please keep in mind that I can only change Ass3.c and Ass3.h.
Please point me to the right direction and if possible can you please give me an example as well. If I need to add more details please excuse me.
Thank you.
Upvotes: 0
Views: 124
Reputation: 53016
Just check if IS_AVAIL
is defined like this
#ifdef IS_AVAIL
#define isAvail() MACRO_DEFINITION_HERE
#else
int isAvail(void) {return ?;}
#endif
where ?
is what should be returned by the function.
Upvotes: 3