Solved

C Puzzle (for fun only!)

Posted on 1998-08-18
18
153 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?

0
Comment
Question by:JYoungman
  • 4
  • 4
  • 4
  • +4
18 Comments
 
LVL 8

Expert Comment

by:Answers2000
ID: 1252137
Not sure the question is very clear - you mean the whole of x

Problem is you can't do address of - &

sizeof ??
0
 
LVL 5

Expert Comment

by:ecw
ID: 1252138
sizeof(x)
0
 
LVL 2

Author Comment

by:JYoungman
ID: 1252139
Yep.  Maybe that one was too easy :-)

0
 
LVL 11

Expert Comment

by:alexo
ID: 1252140
Keep em comming...
0
 
LVL 1

Expert Comment

by:newexpert
ID: 1252141
But remeber register is only a request.  So if somehow computer decide not to grand what's requested then ...
0
 
LVL 1

Expert Comment

by:newexpert
ID: 1252142
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.
0
 
LVL 1

Expert Comment

by:newexpert
ID: 1252143
yuk, they still made implicit reference to the address.
0
 
LVL 1

Expert Comment

by:payn
ID: 1252144
Isn't *x valid?
0
 
LVL 1

Expert Comment

by:newexpert
ID: 1252145
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.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 11

Expert Comment

by:alexo
ID: 1252146
#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.
0
 
LVL 2

Author Comment

by:JYoungman
ID: 1252147
Anybody want to answer this so we can convert it to a PAQ?

0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1252148
"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
0
 
LVL 8

Accepted Solution

by:
Answers2000 earned 0 total points
ID: 1252149
Lock for PAQ:
sizeof is the only operation that works of the whole of x

e.g.
int y = sizeof(x) ;

0
 
LVL 11

Expert Comment

by:alexo
ID: 1252150
>> It can but the syntax rules for register variables still apply AFAIK
Correct.  Same as the C++ "inline" request.
0
 
LVL 4

Expert Comment

by:pagladasu
ID: 1252151
sizeof is OK.
What if you are using a C++ compiler? Won't the address-of(&) work?
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1252152
pagladasu - not on a register variable
0
 
LVL 4

Expert Comment

by:pagladasu
ID: 1252153
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.
0
 
LVL 11

Expert Comment

by:alexo
ID: 1252154
Hmmm...  Just checked the ARM.  He's right, it is permissible in C++.
Live and learn...
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now