I want to improve the readability of the code. So I commented the parameter's direction in the code like this:
#define IN
#define OUT
void Add(IN int Para1, IN int Para2, OUT int& Result);
But I think the compiler will replace every instance of IN and OUT with blank and it could be quite a problem some times.
So is there a better way? Thanks.
(I use C++.)
You can try to put it in comments. That is much better and readable.
void Add(/*IN*/ int Para1, /*IN*/ int Para2, /*OUT*/ int& Result);
Yes: Forget those things and use constness. That will work as long as you don't have a "in" and "out" parameter, which is and should be rarely used.
void foo(int i, const std::string& s, std::vector<char>& out_buf);
// i and s are obviously "in" variables, while out_buf could be both,
// but you can easily show that by giving the parameter a proper name.
Edit: And const correctness does not mean to make value parameters const! This doesn't give the caller any additional information at all, since you can't change his variables either way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With