<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://wiki.kram.nz/index.php?action=history&amp;feed=atom&amp;title=SE250%3Alab-2%3Adols008</id>
	<title>SE250:lab-2:dols008 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.kram.nz/index.php?action=history&amp;feed=atom&amp;title=SE250%3Alab-2%3Adols008"/>
	<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-2:dols008&amp;action=history"/>
	<updated>2026-04-28T22:34:19Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://wiki.kram.nz/index.php?title=SE250:lab-2:dols008&amp;diff=4820&amp;oldid=prev</id>
		<title>Mark: 11 revision(s)</title>
		<link rel="alternate" type="text/html" href="https://wiki.kram.nz/index.php?title=SE250:lab-2:dols008&amp;diff=4820&amp;oldid=prev"/>
		<updated>2008-11-03T05:18:56Z</updated>

		<summary type="html">&lt;p&gt;11 revision(s)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;====Task 1====&lt;br /&gt;
Windows results:&lt;br /&gt;
&lt;br /&gt;
sizeof(ip) = 4;&lt;br /&gt;
&lt;br /&gt;
Linux results:&lt;br /&gt;
&lt;br /&gt;
sizeof(ip) = 4;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Answers:&lt;br /&gt;
&lt;br /&gt;
All pointers that I tried are the same size. Long, float and int are all the same size on the windows machine. I didn&amp;#039;t try everything to save time.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Task 2====&lt;br /&gt;
&lt;br /&gt;
Windows results:&lt;br /&gt;
&lt;br /&gt;
 &amp;amp;x = 0x22ccb8, &amp;amp;y = 0x22ccb0&lt;br /&gt;
 (long)(&amp;amp;x - &amp;amp;y) = 1&lt;br /&gt;
 (long)&amp;amp;x - (long)&amp;amp;y = 4&lt;br /&gt;
&lt;br /&gt;
(long)(&amp;amp;x - &amp;amp;y) finds the difference between the addresses in unit of sizeof(int), whereas (long)&amp;amp;x - (long)&amp;amp;y finds the difference in bytes. Linux results were similar, with different addresses.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Task 3====&lt;br /&gt;
&lt;br /&gt;
&amp;amp;arr = 0x22ccb4&lt;br /&gt;
&lt;br /&gt;
arr+4 = 0x22ccb8&lt;br /&gt;
&lt;br /&gt;
&amp;amp;arr[4] = 0x22ccb8&lt;br /&gt;
&lt;br /&gt;
So arr+4 and &amp;amp;arr[4] are equivalent.&lt;br /&gt;
&lt;br /&gt;
When the array size increased to 10, the difference between &amp;amp;x and &amp;amp;y increased to 32 bytes. Which is odd, considering 16 is a nice round number closer to the 14 actually required. In linux, the compiler shifted the array such that x and y were next to each other, with a difference of 4. Writing past the end of the array (arr[4]) overwrote x.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Task 4====&lt;br /&gt;
&lt;br /&gt;
I&amp;#039;ll keep it short. For the most part globals were similar, but in a seperate memory area. Global variables tend to be further apart like 16 bytes between the integers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Task 5====&lt;br /&gt;
&lt;br /&gt;
The values of p1 and p2 are the addresses of q and r. Am I missing something?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Task 6====&lt;br /&gt;
&lt;br /&gt;
Printing the local strings which have gone out of scope gave unpredictable results. On the windows machine the first string became 456, and the second one became efg because it was overwritten by the call to local_str2. In linux the first string became garbage, and the second became abcdefg. The other strings were as expected.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Task 7====&lt;br /&gt;
&lt;br /&gt;
Struct&lt;br /&gt;
 offsets:&lt;br /&gt;
 my_char: 0&lt;br /&gt;
 my_short: -2&lt;br /&gt;
 my_int: -4&lt;br /&gt;
 my_long: -8&lt;br /&gt;
 my_float: -12&lt;br /&gt;
 my_double: -16&lt;br /&gt;
&lt;br /&gt;
====Task 8====&lt;br /&gt;
&lt;br /&gt;
Union&lt;br /&gt;
 offsets:&lt;br /&gt;
 my_char: 0&lt;br /&gt;
 my_short: 0&lt;br /&gt;
 my_int: 0&lt;br /&gt;
 my_long: 0&lt;br /&gt;
 my_float: 0&lt;br /&gt;
 my_double: 0&lt;br /&gt;
&lt;br /&gt;
Unions store all their variables in the same memory location. This is useful to to interpret the same piece of memory as several different types.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Task 9====&lt;br /&gt;
&lt;br /&gt;
sp3 is allocated the same piece of memory as sp1, because sp1 was free&amp;#039;d. If sp1 is used it will overwrite the data sp3 is pointing to.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Task 10====&lt;br /&gt;
&lt;br /&gt;
Windows:&lt;br /&gt;
&lt;br /&gt;
&amp;amp;local_str = 0x401050&lt;br /&gt;
&lt;br /&gt;
Linux:&lt;br /&gt;
&lt;br /&gt;
&amp;amp;local_str = 0x100004ac&lt;br /&gt;
&lt;br /&gt;
[[User:Dols008|Dols008]] 19:34, 11 March 2008 (NZDT)&lt;/div&gt;</summary>
		<author><name>Mark</name></author>
	</entry>
</feed>