Can a simple a==b 'hang' in and endless loop?

Fredrik Lundh fredrik at pythonware.com
Thu Jan 19 02:06:50 EST 2006


Dave Hansen wrote:

> >Fuzzyman wrote:
> >> I'm not familiar with the C basic datatypes - I assume it has an array
> >> or list like object.
> >>
> >> Would it contain a sequence of poitners to the members ? In which case
> >> they would only be equal if the pointers are the same.
> >>
> >> In this case :
> >>
> >> a = ['some string']
> >> b = ['somestring']
> >> a == b
> >> False (probably)
> >>
> >> Incorrectly using Python syntax for a C example of course :-)
> >>
> >That depends, the C syntax is like this :
> >
> >char *a="hello";
> >char *b="hello";
> >
> >assert(a==b);
> >
> >// true, the compiler knows the two hello are the same and assign the
> >same address(sort of id() in python) to a and b
>
> No. The C standard says the compiler is _allowed_ to re-use character
> literal constants, but is not _required_ to do so.

I could have sworn that fuzzyman's example contained a literal string in
an array, and an array comparision, so why are you talking about com-
paring string literals ?   a compiler for which

    char* a[] = { "some string" };
    char* b[] = { "some string" };

    ...

    if (a == b)
        printf("True\n");

prints True is definitely broken.

</F>






More information about the Python-list mailing list