Difference between revisions of "Workshop 2"

From CDOT Wiki
Jump to: navigation, search
 
(2 intermediate revisions by 2 users not shown)
Line 4: Line 4:
  
 
'''Q:''' Unsigned long longs are the same size as doubles. Currently, unsigned long longs are swapping just fine after being cast as doubles, but I was wondering if we were supposed to differentiate between the two. If so, how can you do it when the only argument is size?<br>
 
'''Q:''' Unsigned long longs are the same size as doubles. Currently, unsigned long longs are swapping just fine after being cast as doubles, but I was wondering if we were supposed to differentiate between the two. If so, how can you do it when the only argument is size?<br>
'''A:''' I was trying to do this with a case for each data type, but we're supposed to cast the void* pointers as char*, and then swap the values byte-by-byte.
+
'''A:''' I was trying to do this with a case for each data type, but we're supposed to cast the void* pointers as char*, and then swap the values byte-by-byte.<br>
 
'''Submitted by:''' Kevin Kofler, Team 9<br><br>
 
'''Submitted by:''' Kevin Kofler, Team 9<br><br>
 +
 +
'''Q:''' How to determine the size of a structure?<br />
 +
'''A:''' Same as primitive types, use sizeof().<br />
 +
BUT - if there are pointers pointing to, say, strings, sizeof() will only count the sizes of these pointers (which is platform dependent, 4 bytes/pointer on Matrix). The actual size of these strings won't be counted. <br />
 +
'''Submitted by:''' Yiqi, Team 5<br /><br />
 +
 +
'''Q:''' When we are swapping structs, and lets say we have two instances of structs, so do we just swap struct1.int1 with struct2.int2? etc..<br />

Latest revision as of 16:40, 23 September 2013

Q:Is the output for workshop 2 still suppose to be time or something else?
A:No, it is supposed to just swap the values of each variables passed to swap function and display them in the main function.
Submitted by: Shayan Vaghei & Mohamed Baig Team#4

Q: Unsigned long longs are the same size as doubles. Currently, unsigned long longs are swapping just fine after being cast as doubles, but I was wondering if we were supposed to differentiate between the two. If so, how can you do it when the only argument is size?
A: I was trying to do this with a case for each data type, but we're supposed to cast the void* pointers as char*, and then swap the values byte-by-byte.
Submitted by: Kevin Kofler, Team 9

Q: How to determine the size of a structure?
A: Same as primitive types, use sizeof().
BUT - if there are pointers pointing to, say, strings, sizeof() will only count the sizes of these pointers (which is platform dependent, 4 bytes/pointer on Matrix). The actual size of these strings won't be counted.
Submitted by: Yiqi, Team 5

Q: When we are swapping structs, and lets say we have two instances of structs, so do we just swap struct1.int1 with struct2.int2? etc..