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?
|