I've taken a C class and now I'm trying to learn Objective-C. One of the things we never really covered in class in great detail was the preprocessor. I've ran across a section in my programming book with some interesting things. I've learned I can inject strings into code by doing the following:
#define str(x) # x str (testing)
Which will cause "testing", included the quotation marks, to be added to my code.
I've also found I can use the ## operator to combine intergers as follows:
#define printx(n) printf("%i\n" x ## n)
printx(10)
which would expand into:
printf("%i\n", x10);
I was wondering if preprocessor macros could be used to do something like the following:
- Get an input string from the user.
- Using a macro, initialize an interger varaible with the name of the variable being the string the user inputed.
For example, if the user were to input "number", the cooresponding line of code would be:
int number;
I would really appreciate any help on this.
Thanks,
helixed


Sign In
Create Account


Back to top









