SE250:lab-2:mcar147

From Marks Wiki
Revision as of 05:19, 3 November 2008 by Mark (Sọ̀rọ̀ | contribs) (16 revision(s))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Back to Lab Reports

Lab 2

First things first, I having installed emacs onto my laptop I had to figure out where it had installed itself, then make a few changes as suggested by John in the lectures. Next I gave up being unable to figure out how anything worked and swapped to using textpad as I actually knew how it worked slightly better. Then there was the problem with getting onto Linux, and the whole first hour of the lab was spent fiddling around achieving nothing. Fun.

Task 1

Using just the lab machine, pointer of all formats had a size of 4, while on the linux server they were also size 4

Task 2

Running the code to find the difference between the addresses, (long)(&x - &y) gave a value of -1, while (long)&x - (long)&y) gave a value of -4. Why, not sure, but with the first the subtraction is done then they are converted while with the 2nd they are converted then subtracted, maybe some data is lost along the way.

When run on the linux server, difference in values was reversed, and the location the values were stored was different

Task 3

I expected the location of y to be pushed back, but for some reason the array was created before the ints, yet leaving the int to be created in the same location. Not knowing why this happened I'm rather confused. The value of &aar[4] is equal to &x, but knowing that arrays in c start at 0, and that the array is before the int, it does make sense. This happened on both normal and linux.

What makes no sense is that when the array is made longer, the values for the address of x and y don't change leaving me rather confused as the values would seem to overlap

Task 4

With the x and y moved to global the array moved to start at the address that y formerly occupied leaving me even more lost as to how the hell it works

Task 5

On the linux server, p1 and p2 strangely have the same value, while on the default p1 is 4 higher than p2, which makes sense due to the fact it seems to like numbering down

Task 6

After making many errors in my code trying to get this thing running, it brought back some strange results:

PC:

sp = 0012FF40(X ↕)
sp = 0012FF40(X ↕)
sp = 0040C010(tuvwxyz)
sp = 009211F0(hijklmn)

Linux:

sp = 0xfff959b4(�þîÐ�)
sp = 0xfff959b4(abcdefg)
sp = 0x10010cd4(tuvwxyz)
sp = 0x10011008(hijklmn)

I have no clue what (X ↕) is or what it means, but it looks rather cool so all good there

Task 7

PC

&my_struct = 138076CE
offsets:
my_char: 0
my_short: -2
my_int: -4
my_long: -8
my_float: -12
my_double: -16

Linux

&my_struct = 0xff8549b0
offsets:
my_char: 0
my_short: -2
my_int: -4
my_long: -8
my_float: -12
my_double: -16

Other than taking a while to type up and longer to fix my copying errors, nothing seems to leap out as unusual, as the types take up the same size on both linux server and the local PC.

Task 8

WHAT!?! PC

&my_struct = 00000000
offsets:
my_char: 0
my_short: 0
my_int: 0
my_long: 0
my_float: 0
my_double: 0

Linux

&my_struct = 0xffc399d8
offsets:
my_char: 0
my_short: 0
my_int: 0
my_long: 0
my_float: 0
my_double: 0

So all the data is in the same place... uhh... Makes no sense but okay... If that is the way the computer tricks itself into saving space then its fine by me

Task 9

The distance between the address is the standard 4 so no space seems to be lost, then when sp1 is freed up, malloc re-assigns it to sp3, however malloc seems to be a very smart command as when sp1 was called after it had been freed, somehow sp3 was assigned to a different location leaving sp1 intact

Task 10

On the PC the function lived at 00401000 while on the Linux it was located at 0x1000046c.

Considering where global values are normally located, this shows that functions are stored very early in the available memory


Chineselegolas Talk 10:25, 11 March 2008 (NZDT)