[OCLUG-devel] Re: [OCLUG] C - Pointer assignment

Chris Smith cbsmith at gmail.com
Mon May 23 12:11:56 PDT 2005


On 5/23/05, Joshua Robinson <joshua.robinson at paulsson.com> wrote:
> myPtr = *(array+1);
> while ( !array ) {
>    *(array++)  = myPtr;
> }

Again, myPtr would normally be a pointer, so for clarity I'd call it
myValue. Still, regardless of it's type, if you can get this to
compile, it'll work.... except for the loop:

while (!array)

That test effectively evaluates to "while the array is null".
Hopefully that loop will always fail. If it does succeed, they you'll
be doing an assignment to address 0, which will cause a segfault. I'm
not sure what you intended with this code (doesn't seem like a bubble
sort to me), but my best guess would suggest something like:

myValue = array[1];
arrayEnd = array + array_length;
while(array != arrayEnd) {
    *(array++) = myValue;
}

-- 
Chris


More information about the OCLUG-devel mailing list