本文介绍了更多宏观问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我已经问了几个关于Macros的问题......并且想想我曾经发生的事情 缺失...所有回复的人都清楚地了解......是 这是一个预处理器动作。 希望以上是真的。 所以,有人可以查看这段代码,并帮助我理解为什么会得到 这个错误。 #include< stdio.h> #define get_char()getc(stdin) #define put_char(x)putc(x,stdout) int main(int argc,const char * argv []){ int c; while((c = get_char)!= EOF)/ *错误:''get_char''未声明 (首次使用此功能)* / put_char(c); 返回0; } 我认为* *会发生什么是get_char将被替换为 " getc(stdin)" 谢谢 解决方案 然后你会想要#define get_char getc(stdin) 请记住,不过,这个很糟糕的使用宏。 上面的程序写得更好如下: #include< stdio.h> int main(无效) { int c; while((c = getchar())!= EOF) putchar(c); 返回0; } 避免使用宏,除非它们的优点超过了它们的优点,这是非常罕见的。 - Richard Heathfield< http://www.cpax.org.uk> 电子邮件:-http:// www。 + rjh @ 谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php> Usenet是一个奇怪的放置" - dmr 1999年7月29日 然后你会想要#define get_char getc(stdin) Richard ...你失去了我我以为这是定义声明 做了什么? 理查德......我毫不怀疑这是真的。我这么做的唯一原因就是看他们是如何工作的**。也许你可以解释为什么它会使用它并且当你倾向于使用它时很少(很少......如下所述!), 就是一个很好的例子。 /> 然后你会想要#define get_char getc(stdin) Richard ...你失去了我我以为这就是定义声明 做了什么? RH' #define get_char getc(stdin) 你定义一个普通的宏与你的对比 #define get_char()getc(stdin) 它定义了一个类似宏的函数。 但是在你的代码中你不能像宏那样使用它: (c = get_char) 所以要么使用 #define get_char getc(stdin) 或 (c = get_char()) 再见,乔乔 I have asked a few questions about Macros...and think what I have beenmissing ...and which all who have replied clearly understand...is thatthis is a Pre-processor action.Hopefully the above is true.So, could someone look at this code, and help me understand why I getthis error.#include <stdio.h>#define get_char() getc(stdin)#define put_char(x) putc(x, stdout)int main (int argc, const char * argv[]) {int c;while ( (c = get_char) != EOF) /* error: ''get_char'' undeclared(first use in this function) */put_char(c);return 0;}I **thought** what would happen is that get_char would be replaced by"getc(stdin)".Thanks 解决方案Then you''ll want #define get_char getc(stdin)Please bear in mind, though, that this is a poor use of a macro.The above program would be better written as follows:#include <stdio.h>int main(void){int c;while((c = getchar()) != EOF)putchar(c);return 0;}Avoid macros except on occasions where their advantages outweigh theirdisadvantages, which is pretty rare.--Richard Heathfield <http://www.cpax.org.uk>Email: -http://www. +rjh@Google users: <http://www.cpax.org.uk/prg/writings/googly.php>"Usenet is a strange place" - dmr 29 July 1999Then you''ll want #define get_char getc(stdin)Richard...you lost me. I thought that is what the define statementdid?Richard...I have no doubt that this is true. The only reason I didthis was to see **how** they work. Perhaps you could explain why it isa poor use and when you tend to use it ( rarely...as noted below!) ,as a good example. Then you''ll want #define get_char getc(stdin)Richard...you lost me. I thought that is what the define statementdid?with RH''s#define get_char getc(stdin)you define a plain macro vs. your#define get_char() getc(stdin)which defines a function like macro.But in your code you don''t use it as a function like macro:(c = get_char)So either use#define get_char getc(stdin)or(c = get_char())Bye, Jojo 这篇关于更多宏观问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-05 19:26