& *

L

Lanarcam

I couldn't find a response in the archives.

Is the following instruction defined by the C language?

int i;

int k = & * i;
 
M

Maarten

I couldn't find a response in the archives.

Is the following instruction defined by the C language?

int i;

int k = & * i;

Have you tried it? What does it even mean?

Maarten

main.c: In function ‘main’:
main.c:6:15: error: invalid type argument of unary ‘*’ (have ‘int’)
 
B

BartC

Lanarcam said:
I couldn't find a response in the archives.

Is the following instruction defined by the C language?

int i;

int k = & * i;

& and * are complementary, in that they tend to cancel each other out (one
creates a pointer to something, one dereferences a pointer).

But, while &*A and *&A do cancel out, the compiler will likely first check
that *A and &A are legal before considering the & or * .

So you example &*i probably won't work, because *i doesn't make sense. But
it might work as *&i, because &i is legal.
 
J

James Kuyper

I couldn't find a response in the archives.

Is the following instruction defined by the C language?

int i;

int k = & * i;

As I indicated in my message a few hours ago, while 6.5.2p3 means that &
and * cancel each other out, it also says "except that the constraints
on the operators still apply". For the '*' operator, there is a
constraint that "The operand of the unary * operator shall have pointer
type." (6.5.2p2). 'i' doesn't have a pointer type, so the above code is
a constraint violation - the C standard does not define its behavior.
 
8

88888 Dihedral

Bartæ–¼ 2012å¹´4月3日星期二UTC+8上åˆ5時16分27秒寫é“:
& and * are complementary, in that they tend to cancel each other out (one
creates a pointer to something, one dereferences a pointer).

But, while &*A and *&A do cancel out, the compiler will likely first check
that *A and &A are legal before considering the & or * .

So you example &*i probably won't work, because *i doesn't make sense. But
it might work as *&i, because &i is legal.

int j;
int* p; // int* a avaiable that can hold and address
p=&j ;// p holds j's address=&j
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top