On the other hand any thread can access any location

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: l here is to use parentheses whenever in doubt about precedence and associativity. For example, in line 6 we could have clearly stated our intent by using the expression (*size)--. 10.11.7 Misunderstanding Pointer Arithmetic Another common mistake is to forget that arithmetic operations on pointers are performed in units that are the size of the objects they point to, which are not necessarily bytes. For example, the intent of the following function is to scan an array of ints and return a pointer to the first occurrence of val. 1 2 3 4 5 6 int *search(int *p, int val) { while (*p && *p != val) p += sizeof(int); /* should be p++ */ return p; } However, because line 4 increments the pointer by four (the number of bytes in an integer) each time through the loop, the function incorrectly scans every fourth integer in the array. 10.11.8 Referencing Non-existent Variables Naive C programmers who do not understand the stack discipline will sometimes reference local variables that are no longer valid, as in the...
View Full Document

Ask a homework question - tutors are online