Link to home
Start Free TrialLog in
Avatar of JYoungman
JYoungman

asked on

C Puzzle (for fun only!)

     register int x[2];
is a valid declaration.  Only one operation on x is
legal, but what is it?

Avatar of Answers2000
Answers2000

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

Problem is you can't do address of - &

sizeof ??
sizeof(x)
Avatar of JYoungman

ASKER

Yep.  Maybe that one was too easy :-)

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.
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.
#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.
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
ASKER CERTIFIED SOLUTION
Avatar of Answers2000
Answers2000

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>> 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.
Hmmm...  Just checked the ARM.  He's right, it is permissible in C++.
Live and learn...