Patch for strstr_binary

Mikael Pettersson mikpe@REDACTED
Tue Dec 13 07:44:01 CET 2005


Dave Smith writes:
 > > These (int) casts are broken on 64-bit machines. Replace them
 > > with (long) casts. Better yet, "index = cur - big_ptr;"
 > > should have the same effect and be 100% kosher.
 > 
 > You have to cast pointers if you want an int out of them, at least  
 > according to my version of gcc. However, I did correct the casts to  
 > be longs instead of ints.

You're computing the difference between two pointers, and that's
well-defined(*) in C since at least K&R: ptr2 - ptr1 returns a
signed integer value diff such that ptr1 + diff == ptr2.
There's no need to fake this by casting the pointers to long first.

(*) Given various conditions, like ptr1 and ptr2 must be of the same
type and point into the same object/array, but those conditions are
satisfied in your code.

/Mikael



More information about the erlang-questions mailing list