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

Dave Hansen iddw at hotmail.com
Thu Jan 19 11:36:34 EST 2006


On Thu, 19 Jan 2006 08:06:50 +0100 in comp.lang.python, "Fredrik
Lundh" <fredrik at pythonware.com> wrote:

>Dave Hansen wrote:
>

[bonono at gmail.com wrote]

>> >Fuzzyman wrote:
[...]
>> >> In this case :
>> >>
>> >> a = ['some string']
>> >> b = ['somestring']
>> >> a == b
>> >> False (probably)
>> >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

I was responding to bonono's example, not fuzzyman's.  Perhaps a more
appropriate response would have been that his example (besides being
incorrect) didn't match the situation under consideration.

>
>    char* a[] = { "some string" };
>    char* b[] = { "some string" };
>
>    ...
>
>    if (a == b)
>        printf("True\n");
>
>prints True is definitely broken.

Definitely.  However,

   if (a[0] == b[0])
      puts("True");

May or may not print "True."  Either answer is allowed.  In C.

Regards,
                                        -=Dave

-- 
Change is inevitable, progress is not.



More information about the Python-list mailing list