Today I am approaching the wonderful community of Code Project, with a question about rewriting functions as macros in C/C++.
I'm currently learning C (and C++), and, as an activity to help me learn more, I'm writing a program that'll take a file, and read it, and then display the data in a way that is useful to the user. The project might be fairly useless, but so far, it has been worth it. (I've been able to learn File I/O, and I took the liberty of learning the basics of pointers, so that I would understand more about how File I/O works in C/C++)
Now, to get to the point of this question:
I wrote a function, that takes a string, and "explodes" it, based on a token (yes, I know there is tokstr, but again, this is for learning). I've been reading about macros lately, and I've gotten mixed-opinions about them.
On one hand, people say "yes, use macros [if you plan on reusing the code]", and on the other, people say "no, macros should be avoided in C++", so I'm sort of trying to figure out, should I invest time in writing a macro to replace this function?
Secondly, I'd like to know (even if I'm not going to write a macro for this function), what should I refrain from doing in a macro? I've also read that you should surround code in your macro(s), with a do/while loop, is there a specific reason?
I do apologize for the long question, but hopefully I'll be able to get some help.
Happy St. Patrick's Day,