#define is unsafe
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 287 Accepted Submission(s): 178
Total Submission(s): 287 Accepted Submission(s): 178
Problem Description
Have you used #define in C/C++ code like the code below?
#include <stdio.h>
#define MAX(a , b) ((a) > (b) ? (a) : (b))
int main()
{
printf("%d\n" , MAX(2 + 3 , 4));
return 0;
}
Run the code and get an output: 5, right?
You may think it is equal to this code:
#include <stdio.h> <
#include <stdio.h>
#define MAX(a , b) ((a) > (b) ? (a) : (b))
int main()
{
printf("%d\n" , MAX(2 + 3 , 4));
return 0;
}
Run the code and get an output: 5, right?
You may think it is equal to this code:
#include <stdio.h> <

本文通过分析HDU2010省赛集训队选拔赛中的问题,揭示了在编程中使用#define可能带来的安全隐患,强调了递归在解决复杂问题时的重要性和安全性。
最低0.47元/天 解锁文章
545

被折叠的 条评论
为什么被折叠?



