由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - C++ Q29: extern and const together
相关主题
再问C++一个C语言概念题
C++ Q67: static (skillport)bloomberg 第一轮电话面试 电经
C++ question面试就是面试问题,跟实际问题差太远
搞不清C++里的constant expressionC++ 一小题
发个电话面经Q in C/C++
请教一个const和non const的C++问题(回忆了几道题)有人做过 select2perfrom 的test吗 ?
C++ Q42: (C22)请教个问题
一道c++ primer的问题问个C/C++概念的问题
相关话题的讨论汇总
话题: extern话题: variable话题: const话题: constant
进入JobHunting版参与讨论
1 (共1页)
c**********e
发帖数: 2007
1
extern const int MaxElements=10;
Which one of the following statements about the declaration in the sample
area above is true?
a) It defines a global constant variable that can be referenced from other
modules.
b) It references the global constant variable MaxElements declared in
another module.
c) It initializes a variable declared in another module.
d) It retrieves the global constant variable MaxElements declared in another
module.
e) It is only legal within an unnamed namespace.
(9_33 a32_48
x***y
发帖数: 633
2
b
c**********e
发帖数: 2007
3
not right.

【在 x***y 的大作中提到】
: b
x***y
发帖数: 633
4
then d? I don't quite the difference between reference and retrieve...

【在 c**********e 的大作中提到】
: not right.
j***i
发帖数: 1278
5
I think is a

【在 x***y 的大作中提到】
: then d? I don't quite the difference between reference and retrieve...
x***y
发帖数: 633
6
define? Not sure, declare seems the right word..

【在 j***i 的大作中提到】
: I think is a
j***i
发帖数: 1278
7
as far as I remember, not sure
In c++ , all built-in declaration is a definition,
const will result internal linkage, but extern turn it to
external linkage.

【在 x***y 的大作中提到】
: define? Not sure, declare seems the right word..
c**********e
发帖数: 2007
8
This question demonstrates the use of extern and const together.
a) It defines a global constant variable that can be referenced from other
modules.
This is correct (C++ Standard 7.1.1/6). It defines a global constant variable that can be referenced from other modules.
b) It references the global constant variable MaxElements declared in
another module.
This is incorrect. The initializer makes it a definition.See other comments.
d) It retrieves the global constant variable MaxElements declared
x***y
发帖数: 633
9
Yes, a is correct. I first thought this is used to refer to variables in
other modules....Actually, extern here seems not necessary...

variable that can be referenced from other modules.
comments.
another

【在 c**********e 的大作中提到】
: This question demonstrates the use of extern and const together.
: a) It defines a global constant variable that can be referenced from other
: modules.
: This is correct (C++ Standard 7.1.1/6). It defines a global constant variable that can be referenced from other modules.
: b) It references the global constant variable MaxElements declared in
: another module.
: This is incorrect. The initializer makes it a definition.See other comments.
: d) It retrieves the global constant variable MaxElements declared

c**********e
发帖数: 2007
10
why extern not necessary? Doesn't it make the variable available to other
compilation unit?

【在 x***y 的大作中提到】
: Yes, a is correct. I first thought this is used to refer to variables in
: other modules....Actually, extern here seems not necessary...
:
: variable that can be referenced from other modules.
: comments.
: another

相关主题
请教一个const和non const的C++问题一个C语言概念题
C++ Q42: (C22)bloomberg 第一轮电话面试 电经
一道c++ primer的问题面试就是面试问题,跟实际问题差太远
进入JobHunting版参与讨论
s*********t
发帖数: 1663
11
I agree with you that extern is not necessary if a) is the answer here

【在 x***y 的大作中提到】
: Yes, a is correct. I first thought this is used to refer to variables in
: other modules....Actually, extern here seems not necessary...
:
: variable that can be referenced from other modules.
: comments.
: another

M******q
发帖数: 94
12
I think extern is necessary. "const" by default has internal linkage by c++
rules. "extern" gives it external linkage so that other modules can access
the var.

【在 s*********t 的大作中提到】
: I agree with you that extern is not necessary if a) is the answer here
x***y
发帖数: 633
13
By default, the global variable can be shared by all the translate units
except you delcare it as static...
I verified in the programme again, and extern is not necessary....In my
opinion, extern is the storage specifier, as auto, register and static; and
const is the attribute specifier, as volatile, mutable....

【在 c**********e 的大作中提到】
: why extern not necessary? Doesn't it make the variable available to other
: compilation unit?

t****t
发帖数: 6806
14
const makes namespace scope names internal linkage unless extern is
specified. (3.5 clause 3)

and

【在 x***y 的大作中提到】
: By default, the global variable can be shared by all the translate units
: except you delcare it as static...
: I verified in the programme again, and extern is not necessary....In my
: opinion, extern is the storage specifier, as auto, register and static; and
: const is the attribute specifier, as volatile, mutable....

x***y
发帖数: 633
15
Sorry, I made a mistake. You are right. when using const, we must have
extern to make it have the external linkage.

【在 t****t 的大作中提到】
: const makes namespace scope names internal linkage unless extern is
: specified. (3.5 clause 3)
:
: and

1 (共1页)
进入JobHunting版参与讨论
相关主题
问个C/C++概念的问题发个电话面经
问个C++的题目请教一个const和non const的C++问题
Hashtable 问题C++ Q42: (C22)
Amazon.com recruiting event in Minneapolis, MN- Hiring SDE's一道c++ primer的问题
再问C++一个C语言概念题
C++ Q67: static (skillport)bloomberg 第一轮电话面试 电经
C++ question面试就是面试问题,跟实际问题差太远
搞不清C++里的constant expressionC++ 一小题
相关话题的讨论汇总
话题: extern话题: variable话题: const话题: constant