由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 深情的呼唤师傅们!C++做题做不出来啦!
相关主题
这个结果是啥,为什么呢?关于程序必须支持win and linux, 可不可以用class而不是#ifdef WIN32 ?
what kind of language this is and how to change it? (转载)C++ template preprocessor
问低级问题how to apply OOD to a code for both win and linux platform ?
弱问一个ifdef 和ifndefCPP question
【请教】mpicc 和 mpiCC编译问题三个C syntax 弱问题
又一个初级问题: C++中多如牛毛的#define格式请教template和factory有啥区别?
C++ Q 99-102 (转载)one question about operator delete
C#中如何share Pre-processing directivesIs this correct?
相关话题的讨论汇总
话题: line话题: language话题: error话题: macro话题: warning
进入Programming版参与讨论
1 (共1页)
z****e
发帖数: 2024
1
Which of the following statements correctly describe the code below in C++?
#define language 437 //Line 1
#if language < 400
#undef language //Line 2
#else //Line 3
#define language 850 //Line 4
#ifdef language //Line 5
printf("%d", language); //Line 6
#endif
#endif
A. An error or warning will occur on Line 6 because a macro cannot be used
as part of a preprocessor directive.
B. An error or warning will occur on Line 2 because #undef is not a valid
preprocessor directive.
C. An error or warning will occur on Line 4 because language has already
been defined.
D. If Line 1 is changed to #define language 300, Line 6 will print "850".
E. An error or warning will occur on Line 3 because #else can only be used
as the last conditional in the chain.
===================================================
我怎么觉得没一个对的呢?
C看着沾边,但是原因也不是"has already been defined.", 而是重定义时候的数值不
是437,如果是437,重定义没问题。但是这个“重定义”可能也就不算是“重定义”了。
有个大牛哥们说D,我怎么觉得执行不到,也打印不出呢?
至于A,放在main里边,完全没问题。
这题目肯定是有个答案, 而且是个多选题。
师傅们,弟子又迷途了,你们老人家都快出来渡我吧!
z****e
发帖数: 2024
2
另外,到底什么是macro,什么是preprocessor directives
b***i
发帖数: 3043
3
codepad.org

【在 z****e 的大作中提到】
: Which of the following statements correctly describe the code below in C++?
: #define language 437 //Line 1
: #if language < 400
: #undef language //Line 2
: #else //Line 3
: #define language 850 //Line 4
: #ifdef language //Line 5
: printf("%d", language); //Line 6
: #endif
: #endif

p***o
发帖数: 1252
4
g++/gcc都说是 C, 看起来也靠谱。

【在 z****e 的大作中提到】
: Which of the following statements correctly describe the code below in C++?
: #define language 437 //Line 1
: #if language < 400
: #undef language //Line 2
: #else //Line 3
: #define language 850 //Line 4
: #ifdef language //Line 5
: printf("%d", language); //Line 6
: #endif
: #endif

k**********g
发帖数: 989
5
C: 留意 "warning" 一字
基本上是考小心眼,很un-American
l*********s
发帖数: 5409
6
Thanks !

【在 b***i 的大作中提到】
: codepad.org
z****e
发帖数: 2024
7
不错,如此, 非C莫属。

【在 k**********g 的大作中提到】
: C: 留意 "warning" 一字
: 基本上是考小心眼,很un-American

t****t
发帖数: 6806
8
actually it's an error, not warning.
[16.3 Macro replacement]
2 An identifier currently defined as an object-like macro may be redefined
by another #define preprocessing directive provided that the second
definition is an object-like macro definition and the two replacement lists
are identical, otherwise the program is ill-formed. Likewise, an identifier
currently defined as a function-like macro may be redefined by another #
define preprocessing directive provided that the second definition is a
function-like macro definition that has the same number and spelling of
parameters, and the two replacement lists are identical, otherwise the
program is ill-formed.

【在 k**********g 的大作中提到】
: C: 留意 "warning" 一字
: 基本上是考小心眼,很un-American

p***o
发帖数: 1252
9
Would ill-formed demand a compiling error?

lists
identifier

【在 t****t 的大作中提到】
: actually it's an error, not warning.
: [16.3 Macro replacement]
: 2 An identifier currently defined as an object-like macro may be redefined
: by another #define preprocessing directive provided that the second
: definition is an object-like macro definition and the two replacement lists
: are identical, otherwise the program is ill-formed. Likewise, an identifier
: currently defined as a function-like macro may be redefined by another #
: define preprocessing directive provided that the second definition is a
: function-like macro definition that has the same number and spelling of
: parameters, and the two replacement lists are identical, otherwise the

t****t
发帖数: 6806
10
hmm....you are right, it's not required for error.
[1.4 Implementation compliance]
8 A conforming implementation may have extensions (including additional
library functions), provided they do not alter the behavior of any well-
formed program. Implementations are required to diagnose programs that use
such extensions that are ill-formed according to this International Standard
. Having done so, however, they can compile and execute such programs.

【在 p***o 的大作中提到】
: Would ill-formed demand a compiling error?
:
: lists
: identifier

1 (共1页)
进入Programming版参与讨论
相关主题
Is this correct?【请教】mpicc 和 mpiCC编译问题
基于macro的meta programming真难懂又一个初级问题: C++中多如牛毛的#define格式
输入输出流,stl,api精通各需要多长时间?C++ Q 99-102 (转载)
师傅们,C++概念题,弟子有礼了C#中如何share Pre-processing directives
这个结果是啥,为什么呢?关于程序必须支持win and linux, 可不可以用class而不是#ifdef WIN32 ?
what kind of language this is and how to change it? (转载)C++ template preprocessor
问低级问题how to apply OOD to a code for both win and linux platform ?
弱问一个ifdef 和ifndefCPP question
相关话题的讨论汇总
话题: line话题: language话题: error话题: macro话题: warning