Unread post Thu Jan 20, 2011 1:09 pm

Lecture 01/20 related

I was supposed to follow up on a couple of issues raised during Thursday's lecture:

- the size_t issue: it is available in C99, it's available in C++. You can use it in CUDA as well, you can follow the C++ syntax: declare a variable wherever you use it the first time, don't have to do so at the beginning of a function. You don't have to include any header file in order to use size_t

- i attached a MS-Word document to this post (pointerRelated.docx) with the arr[0]=266 example. I used the byte order that is in common use. My discussion in class had the byte/bit order mirrored, which produced the correct answer but didn't use the byte order that is commonly used. Moreover, when i tried to change it on the fly during class i ended up with a hybrid which probably confused people even more.

- my statement that accessing the heap after memory being freed causes a crash was indeed incorrect. While you should indeed not access heap memory that was freed, if you do so it's not going to cause a crash. In other words, the code below is not causing a crash but it's an illustration of a bad practice that would typically lead to a bug in a real program:
  Code:

int main(int argc, char** argv)
{
   int* p;
   int arr[2];
   arr[0] = 1;
   arr[1] = 2;

   p = (int*) malloc(sizeof(int)*100);
   free( p );
   p[34] = arr[1] * 3;
   return 0;
}


Thank you for pointing out mistakes and for your comments.
Attachments
pointerRelated.docx
(112.33 KiB) Downloaded 375 times