Could the order of operation be the problem with the first?  Have you tried
grouping the parameters?
>    // always generates run-time
>   if(tmpChar != ':' && tmpChar != ';')  { // some code }
change to
if((tempChar != ';') && (tempChar != ';'))

That cleared up a problem I was having a couple of weeks ago.

Dave

-----Original Message-----
From: Mike Davis <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: Sunday, April 18, 1999 10:35 PM
Subject: Pointer Error question


I have a strange problem that is driving me nuts (easily done).

I have a function that is passed a pointer to char.  I then
parse the string pointed to by the pointer.  I check the
characters and decide if I want to stop.

Anyway, the first way I tried to do this always produced an
error so I came up with a different way.  The second way
never produces an error.

I'm wondering if someone can tell me the difference and why one
causes a run-time error and one does not?  The pointer (ptr) is
initialized and points to a valid number.  The character tested
may be NULL, if end of string is reached.  The first 'if' statement
always generates an error and the 2nd does not.  Why?

int TestFunction(char * ptr)
{
    char tmpChar;
    tmpChar = *ptr; // *ptr may be NULL

    // always generates run-time
    if(tmpChar != ':' && tmpChar != ';')  { // some code }

    // never generates run-time error
    if(*ptr != ':' && *ptr != ';')  { // some code }

// additional code not shown

What is the technical difference that might cause one to generate
a run-time error and one does not?


--
-----------------------------------------------------------------
Discussion Group:        http://www.halcyon.com/ipscone/wwwboard/

Protect your constitutional rights. Your favorite one may be next!
-----------------------------------------------------------------




Reply via email to