We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

C Puzzle (for fun only!)

JYoungman
JYoungman asked
on
Medium Priority
172 Views
Last Modified: 2010-04-15
     register int x[2];
is a valid declaration.  Only one operation on x is
legal, but what is it?

Comment
Watch Question

Not sure the question is very clear - you mean the whole of x

Problem is you can't do address of - &

sizeof ??
ecw

Commented:
sizeof(x)

Author

Commented:
Yep.  Maybe that one was too easy :-)

Commented:
Keep em comming...
But remeber register is only a request.  So if somehow computer decide not to grand what's requested then ...
The following 4 operations are also valid: x[0], x[1], 1[x], 0[x]
although you can argue they are too similar to be 4.
yuk, they still made implicit reference to the address.

Commented:
Isn't *x valid?
Nope.  Remember you can't directly or indirectly refer to x's address, so how can you dereference x's address?

The only other pseudo-operation is #x, which gets interpreted as "x" by compiler.

Commented:
#x is textual substitution done py the preprocessor befor the compiler gets to look at the code.  It has no relation to the x variable.

Author

Commented:
Anybody want to answer this so we can convert it to a PAQ?

"But remeber register is only a request.  So if somehow computer decide not to grand [grant ?] what's requested then ..."
It can but the syntax rules for register variables still apply AFAIK
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Commented:
>> It can but the syntax rules for register variables still apply AFAIK
Correct.  Same as the C++ "inline" request.
sizeof is OK.
What if you are using a C++ compiler? Won't the address-of(&) work?
pagladasu - not on a register variable
Answers2000-The address-of operator works on register variable in C++ - try it out with the VC++ compiler yourself and see. Also please check out the latest book on the C++ programming language by Bjarne Stroustrup.

Commented:
Hmmm...  Just checked the ARM.  He's right, it is permissible in C++.
Live and learn...
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.