Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

A11: What is the output of *(&b+4) if "int b" is a parameter?

22 views
Skip to first unread message

Yifan

unread,
Apr 1, 2012, 2:08:21 AM4/1/12
to
For example:

int wain(int *a, int b) {
return *(&b+4);
}

what should be store in $3 ?
Can we get the value of &b ?

Thanks.

jason tran

unread,
Apr 1, 2012, 8:07:39 PM4/1/12
to
I think, it should put in $3 whatever is in the address that is 4
bytes after b.

address---------
a | some address to int somewhere in memory, that holds
first element in the array |
---------
&b | b |
---------
&b+4 | g22g |
----------

The way the class structured the memory, it should produce one of the
values that was saved in the prologue, i think (depends how you
ordered the parameters).
But it doesnt matter i think, it just some garbage value.

Jeremy Roman

unread,
Apr 3, 2012, 12:15:31 AM4/3/12
to
The output of this program is undefined. The WLPP specification does not
tell you what the layout of your variables should be in memory. Most
implementations will produce whatever (probably garbage or zero) word
happens to be 4 words (not bytes) after b in memory.

Though since what's there is undefined, simply generating "jr $31" is a
reasonable program, since it also does nothing but produce an undefined
output (just like the WLPP source).

0 new messages