0

I have defined two macros

#define the_begin begin = 0
#define the_size  n - begin

I'd like to check if the_size macro is not been used without the_begin since it depends on the_begin.

Is it possible to check such dependence?

4

1 回答 1

4

The dependency is already implicitly introduced by using the begin variable. If you give it a more unique name, you can mostly be sure that they won't be misused.

You can't be 100% sure, of course, because macros expand to regular text. Specially crafted text will always be able to imitate the effect of a macro, because that's what macros are.

All that said, what you're doing is a very, very bad idea. Macros such as those have a direct, negative impact in the ability of a reader to understand the code. Specially because, being macros, they can expand to anything -- and the final code that gets executed does not reflect what's written.

That's a good recipe for a long night of debugging.

于 2013-03-30T22:36:56.153 回答