Is writing this *(&x)
in my code any different than x
? Or does the compiler make them the same thing?
Asked
Active
Viewed 90 times
1

Rorschach
- 31,301
- 5
- 78
- 129
-
What is `x`? Without knowing that your question doesn't make any sense. – D Drmmr Apr 18 '14 at 06:29
-
@DDrmmr `x` is just a variable... – Rorschach Apr 18 '14 at 06:31
-
Well in C we have the following wording in the standard [If the operand is the result of a unary * operator, neither that operator nor the & operator is evaluated and the result is as if both were omitted](http://stackoverflow.com/a/21247407/1708801) as far as I know we don't equivalent wording in C++. – Shafik Yaghmour Apr 18 '14 at 06:36
3 Answers
3
GCC at least appears to generate the same instructions for both *(&x)
and just x
assuming that whatever type x
is doesn't overload the &
and *
operators.

PomfCaster
- 812
- 1
- 7
- 12
-
-
You can use the `-S` flag for GCC, there are also a few websites that are able to do it like http://assembly.ynh.io/ – PomfCaster Apr 18 '14 at 06:31
3
It certainly doesn't help readability.
As long as there's no operator overloading going on it is almost certain that the compiler would generate identical code for the two. Compile to assembly (-S
in gcc
) to see for yourself.

NPE
- 486,780
- 108
- 951
- 1,012
1
Is writing this *(&x) in my code any different than x?
They might mean different thing if *
or/and &
are overloaded operators, else *(&x)
and x
mean the same thing, in which case it decreases readability and so you wouldn't like to write that. See this similar topic:
Hope that helps.