鱼C论坛

 找回密码
 立即注册
查看: 880|回复: 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
  1. //宏定义,2022.2.19。
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include<conio.h>

  5. #define M 12
  6. //#define M 13
  7. //#define M 500
  8.         
  9. #if     M < 13
  10. #undef  M
  11. #define M 13
  12. #endif                   // 加上这行
  13. //#error
  14. #if     M < 500
  15. #define N M / 2 - M / 10
  16. #else
  17. #define N M / 5
  18. #endif

  19. int main(void)
  20. {
  21.    printf("M = %d, N = %d", M, N);
  22.    getch();
  23.    return 0;
  24. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

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

  5. #define M 12
  6. //#define M 13
  7. //#define M 500
  8.         
  9. #if     M < 13
  10. #undef  M
  11. #define M 13
  12. #endif                   // 加上这行
  13. //#error
  14. #if     M < 500
  15. #define N M / 2 - M / 10
  16. #else
  17. #define N M / 5
  18. #endif

  19. int main(void)
  20. {
  21.    printf("M = %d, N = %d", M, N);
  22.    getch();
  23.    return 0;
  24. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-3-14 22:24:27 | 显示全部楼层
@isdkz,太感谢啦,这里拜谢啦,老大;very good!
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-4-24 19:19

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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