On Mon, 19 Apr 1999, Dave Lippincott wrote:
> 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 != ';'))
No, that's not the problem I tried that before I posted this and
it makes no difference.
I think it has something to do with this 'if' statement
not being seen as true if, (tmpChar != ':' && tmpChar != ';'),
but the if (*ptr != ':' && *ptr != ';') is seen as true. Or
trying to do an operation that is not legal.
There is other code associated with this problem. If the
'if' statement is true, execution ends. If the 'if' statement
is false, the ptr is incremented and other code is executed.
I also wonder about a NULL condition in the 'if' statement. In the
case of the first statement the comparrison is possibly like:
if (NULL != ':' && NULL != ';') while the second is:
if (*ptr != ':' && *ptr != ';'); never uses NULL directly. Since tmpChar
might have been previously assigned to NULL, this might be the source
of my problem.
Does anyone know if that is the problem?
>
> 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!
> -----------------------------------------------------------------
>
>
>
>
>
>
----------------------------------------------------
Shoot-to-Win
Protect the 2nd Amendment
----------------------------------------------------