SE250:lab-2:hbar055

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

Number 1

Are all the pointers the same size? The first question required for the user to check the size of each data types and compare them

Windows: int = 4 Short = 4 Float = 4 Double = 4 char = 4

Linux: int = 4 Short = 4 Float = 4 Double = 4 char = 4

The result shows that the size of the data types are the same.


Number 2

What is the difference between (long)(&x - &y) and (long)&x - (long)&y?

For (long)(&x - &y), it will give: Windows: &x = 0x22ccc4, &y = 0x22ccc0, diff = 1

Linux: &x = 0xffb8c71c, &y = 0xffb8c718, diff = 1

For (long)&x - (long)&y, it will give: Windows: &x = 0x22ccc4, &y = 0x22ccc0, diff = 4

Linux: &x = 0xffbb371c, &y = 0xffbb3718, diff = 4


Number 3

What is the size of the array?

Windows: 4 Linux: 4

What is the address of arr? What are the values of &arr, arr+4 and arr[4]?

Windows: arr = 0x22ccc0 &arr = 2280640 arr+4 = 2280644 &arr[4] = 2280644

Linux: arr = 0x22ccc0 &arr = 2280640 arr+4 = 2280644 &arr[4] = 2280644

Print out the values of x and y

Difference between x & y when arr is zero:

Arr = 0:

Windows: &x = 0x22ccbc, &y = 0x22cc9c, diff = 8 Linux: &x = 0xffb6871c, &y = 0xffb68718, diff = 1

Arr = 1:

Windows: &x = 0x22ccc4, &y = 0x22ccbc, diff = 2 Linux: &x = 0xff883718, &y = 0xff883714, diff = 1

Arr = 2:

Windows: &x = 0x22ccc4, &y = 0x22ccbc, diff = 2 Linux: &x = 0xff9c9718, &y = 0xff9c9714, diff = 1

Arr = 3:

Windows: &x = 0x22ccbc, &y = 0x22cc9c, diff = 8 Linux: &x = 0xff8f9718, &y = 0xff8f9714, diff = 1

Arr = 4:

Windows: &x = 0x22ccc4, &y = 0x22ccbc, diff = 2 Linux: &x = 0xff96371c, &y = 0xff963714, diff = 2

Arr = 5:

Windows: &x = 0x22ccbc, &y = 0x22cc9c, diff = 8 Linux: &x = 0xffc0871c, &y = 0xffc08718, diff = 1

Arr = 6:

Windows: &x = 0x22ccbc, &y = 0x22cc9c, diff = 8 Linux: &x = 0xffba171c, &y = 0xffba1718, diff = 1

Arr = 7:

Windows: &x = 0x22ccbc, &y = 0x22cc9c, diff = 8 Linux: &x = 0xffd2a71c, &y = 0xffd2a718, diff = 1

Arr = 8:

Windows: &x = 0x22ccc4, &y = 0x22ccb4, diff = 4 Linux: &x = 0xffe98710, &y = 0xffe9870c, diff = 1

Arr = 9:

Windows: &x = 0x22ccbc, &y = 0x22cc9c, diff = 8 Linux: &x = 0xffc0670c, &y = 0xffc06708, diff = 1

Arr = 10:

Windows: &x = 0x22ccbc, &y = 0x22cc9c, diff = 8 Linux: &x = 0xfff0770c, &y = 0xfff07708, diff = 1


Reverting the size to 4, we get:

Windows: x = 10, y = 0 Linux: x = 167772160, y = 0


Number 4

Repeat Task2 and Task3 with x and y variables being globel variables.

Windows results: size of array = 4 &arr = 0x403030 arr+4 = 0x403034 &arr[4] = 0x403034 &x = 0x403040 &y = 0x403020 diff = 8 diff = 32


Linux results: size of array = 4 &arr = 0x10010ee4 arr+4 = 0x10010ee8 &arr[4] = 0x10010ee8 &x = 0x10010ee0 &y = 0x10010ee8 diff = -2 diff = -8



Number 5

Windows results: p1 = 0x22ccb8 p2 = 0x22ccb0 &q = 0x22ccb8 &r = 0x22ccb0

Linux results: p1 = 0x7fffffc4c4e8 p2 = 0x7fffffc4c4e0 &q = 0x7fffffc4c4e8 &r = 0x7fffffc4c4e0

As expected, p1 equals the address, of q, and likewise for p2 and r. I tried the code with the curly braces, as shown in the handout, but the compiler threw errors about q and r having not been declared when it reached the print line. I'm not sure what was supposed to happen with the braces, it it seemed to just make the compiler ignore the contents of the braces.


Number 6

Windows results: sp = 0x22cca0(456) sp X'd = 0x22cca0('1@) sp = 0x22cca0(efg) sp X'd = 0x22cca0('1@) sp = 0x402000(tuvwxyz) sp X'd = 0x402000(XXXXXXX) sp = 0x670178(hijklmn) sp X'd = 0x670178(XXXXXXX)

Linux results: sp = 0x7fffff982660(0123456) sp Xd = 0x7fffff982660(XXXXXXX) sp = 0x7fffff982660(abcdefg) sp Xd = 0x7fffff982660(XXXXXXX) sp = 0x601228(tuvwxyz) sp Xd = 0x601228(XXXXXXX) sp = 0x602010(hijklmn) sp Xd = 0x602010(XXXXXXX)