C++/how to pass paramters from c++ program to a macro
I have a C++ program which runs a few macros, i need it to pass the username, pwd and another variable to the macro. How do i do that?
First off, lets define a macro to use an an example here.
There is a couple different ways to do this. You can have the macro call a function, or you can do all the processes in the macro itself. First lets take a look at how to use a function in the macro. We can also use the preprocessor to determine which functions you want to use if it differs from debug and release configurations.
#define STORE_DATA(name, password) FunctionDebug(name, password)
#define STORE_DATA(name, password) FunctionRelease(name, password)
Here is the alternate way to do this and process the data in the macro itself.
// in main
#define STORE_DATA(name, password) strcpy(Bob.name, name); strcpy(Bob.password, password);
const char *pName = "Bob";
const char *pPassword = "Test";
When you define a macro, it does not get a regular parameter list like a normal function. You define it with a word or letter or whatever you wish. Since a macro is nothing more than a copy and paste to the compiler, all works out fine. Also, a macro must be defined all on the same line. You can use the \ symbol which tells the compiler to skip to the next line for the readability sake of your code.
I hope this information was of help to you.