由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - register variable
相关主题
How to use volatile in c++?准备面试一个java-based position,有什么书推荐一下?
an interview question关于linked list的copy cstr和dstr
how to implement singleton without static variable?question for C++ constant
stl的nth_element的复杂度是不是O(N)?请推荐一本语言方面的C++书籍
which style do you prefer?C++ vector 一边遍历一边删
请教template和factory有啥区别?post increment
An interesting C++ compile errorwhat is the most efficient way to trim a string in C++?
[合集] thinking in c++ 这书如何?C++class指针转换
相关话题的讨论汇总
话题: register话题: variable话题: int话题: book话题: address
进入Programming版参与讨论
1 (共1页)
n**d
发帖数: 9764
1
This code works! Is it said we could not take address of register variable?
int main() {
register int a;
int *p;
a = 8;
p = &a;
cout << "a=" << *p < } ///:~
t****t
发帖数: 6806
2
7.1.1
3 A register specifier has the same semantics as an auto specifier
together with a hint to the implementation that the object so declared
will be heavily used. [Note: the hint can be ignored and in most
implementations it will be ignored if the address of the object is
taken. --end note]

【在 n**d 的大作中提到】
: This code works! Is it said we could not take address of register variable?
: int main() {
: register int a;
: int *p;
: a = 8;
: p = &a;
: cout << "a=" << *p <: } ///:~

n**d
发帖数: 9764
3
Which book?
Thinking in C++ V3 one:
Register variables
...
There are restrictions to the use of register variables. You cannot take or
compute the address of a register variable. A
register variable can be declared only within a block (you cannot have
global or static register variables). You can, however, use a register
variable as a formal argument in a function (i.e., in the argument list).

【在 t****t 的大作中提到】
: 7.1.1
: 3 A register specifier has the same semantics as an auto specifier
: together with a hint to the implementation that the object so declared
: will be heavily used. [Note: the hint can be ignored and in most
: implementations it will be ignored if the address of the object is
: taken. --end note]

t****t
发帖数: 6806
4
"you can not take the address of a register variable" means if you do, then
it is no longer a register variable
my quote is from the c++ standard, if any other book is against it, the book
must be not precise or could be even wrong

or

【在 n**d 的大作中提到】
: Which book?
: Thinking in C++ V3 one:
: Register variables
: ...
: There are restrictions to the use of register variables. You cannot take or
: compute the address of a register variable. A
: register variable can be declared only within a block (you cannot have
: global or static register variables). You can, however, use a register
: variable as a formal argument in a function (i.e., in the argument list).

n**d
发帖数: 9764
5
why not directly say the book is wrong?

then
book

【在 t****t 的大作中提到】
: "you can not take the address of a register variable" means if you do, then
: it is no longer a register variable
: my quote is from the c++ standard, if any other book is against it, the book
: must be not precise or could be even wrong
:
: or

t****t
发帖数: 6806
6
because it is not wrong..."can not" itself is not a precise word, it doesn't
say if you do it, what will happen. for a book, it is ok to say that.

【在 n**d 的大作中提到】
: why not directly say the book is wrong?
:
: then
: book

n**d
发帖数: 9764
7
political answer.

't

【在 t****t 的大作中提到】
: because it is not wrong..."can not" itself is not a precise word, it doesn't
: say if you do it, what will happen. for a book, it is ok to say that.

t****t
发帖数: 6806
8
what answer do you want?
why do i meet so many egghead today?

【在 n**d 的大作中提到】
: political answer.
:
: 't

n**d
发帖数: 9764
9
You do answer the question very well. Thanks! We have different opinion to
the words from TIC which is misleading readers.

【在 t****t 的大作中提到】
: what answer do you want?
: why do i meet so many egghead today?

1 (共1页)
进入Programming版参与讨论
相关主题
C++class指针转换which style do you prefer?
第五版的 c++ primer 出来了请教template和factory有啥区别?
C++ 11 课程 (视频 ):Rvalue ReferenceAn interesting C++ compile error
C++项目大部分失败了,统计数据在哪里?[合集] thinking in c++ 这书如何?
How to use volatile in c++?准备面试一个java-based position,有什么书推荐一下?
an interview question关于linked list的copy cstr和dstr
how to implement singleton without static variable?question for C++ constant
stl的nth_element的复杂度是不是O(N)?请推荐一本语言方面的C++书籍
相关话题的讨论汇总
话题: register话题: variable话题: int话题: book话题: address