鱼C论坛

 找回密码
 立即注册
查看: 730|回复: 2

[已解决]宏定义的使用纠错,谢谢。

[复制链接]
发表于 2022-3-14 22:17:41 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
如题:下面程序无法编译,编译错误为:文件中的#if/#endif对不匹配;应该如何修改?求助各位大佬,拜谢啦。

//宏定义,2022.2.19。
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>

#define M 12
//#define M 13
//#define M 500
        
#if     M < 13
#undef  M
#define M 13
//#error
#if     M < 500
#define N M / 2 - M / 10
#else
#define N M / 5
#endif

int main(void)
{
   printf("M = %d, N = %d", M, N);
   getch();
   return 0;
}
最佳答案
2022-3-14 22:19:33
//宏定义,2022.2.19。
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>

#define M 12
//#define M 13
//#define M 500
        
#if     M < 13
#undef  M
#define M 13
#endif                   // 加上这行
//#error
#if     M < 500
#define N M / 2 - M / 10
#else
#define N M / 5
#endif

int main(void)
{
   printf("M = %d, N = %d", M, N);
   getch();
   return 0;
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-3-14 22:19:33 | 显示全部楼层    本楼为最佳答案   
//宏定义,2022.2.19。
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>

#define M 12
//#define M 13
//#define M 500
        
#if     M < 13
#undef  M
#define M 13
#endif                   // 加上这行
//#error
#if     M < 500
#define N M / 2 - M / 10
#else
#define N M / 5
#endif

int main(void)
{
   printf("M = %d, N = %d", M, N);
   getch();
   return 0;
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-3-14 22:24:27 | 显示全部楼层
@isdkz,太感谢啦,这里拜谢啦,老大;very good!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-10-5 12:28

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表