English 中文(简体)
Macros in C. 请提供解决办法
原标题:Macros in C.... please give the solution

Suppose I 宣布了一个宏观名称,xyz()

现在,我在第二次会议上正在创建另一个宏观<代码>xyz1()和参照第1个宏观(即xyz(<>)。

最后,Ill还创立了另一个宏观xyz2()和第三版第二版。

Now my question is: is this correct (it s executing without any problem)? Macro xyz() is defined twice. Why its not giving an error? What is the solution?

问题回答

无,只有一度界定第一个宏观wiil。 页: 1

#define Symbol SymbolResolution

预处理器将取代<代码>Symbol>>。 凡是见Symbol。 如果Symbol Resolution is a #define , or includes some sign that have #define s within same will be used to them, they will all be amended. 直到没有在整个翻译单位有<代码>#define的符号。

因此,你可以像你所希望的那样,参考其他宏观。 然而,你可以追溯性地参照宏观。 你们也应谨慎从事这项工作——如果你滥用宏观方法,这很容易导致难以读懂的很多东西,而且很难减少编码。

如果你指其他宏观,就是合法的。

When the preprocessor expands a macro name, the macro s expansion replaces the macro invocation, then the expansion is examined for more macros to expand.

#define hello() (12)
#define test() (1+hello())

然而,宏观呼吁本身并非合法。

A self-referential macro is one whose name appears in its definition. Recall that all macro definitions are rescanned for more macros to replace. If the self-reference were considered a use of the macro, it would produce an infinitely large expansion. To prevent this, the self-reference is not considered a macro call.





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签