Patch for strstr_binary

Håkan Huss <>
Tue Dec 13 13:10:05 CET 2005


2005/12/13, Mikael Pettersson <>:
> > +    if (is_binary(big) && is_binary(little)) {
> > +
> > +        char* big_ptr;
> > +        int big_len = binary_size(big);
> > +        GET_BINARY_BYTES(big, big_ptr);
> > +
> > +        char* little_ptr;
> > +        int little_len = binary_size(little);
> > +        GET_BINARY_BYTES(little, little_ptr);
> > +
> > +        char* cur;
> > +        char* max_big = (big_ptr + big_len) - little_len ;
> > +        char  first_little = *little_ptr;
> > +        int   index = -1;
>
> This isn't ANSI-C and won't compile with e.g. gcc-2.95.3.
> You should make a single block of the variable declarations
> at the beginning of this scope, and do the initialisations
> as assignments.
>

It is ANSI-C, since it is allowed by the current ANSI/ISO definition
of the C language, (ISO 9899:1999 if memory serves me right, aka C99).
It is not allowed by the previous ANSI standard, C89, which was
formally obsoleted some six years ago. Even though it's true that
there are all to many broken compilers out there (from a C99 point of
view) and gcc is one of them, mixing declarations and code does work
in gcc 3.0 and later. Gcc 3.0 was released in june 2001, so we're not
really talking bleeding edge here...

Regards,
Håkan



More information about the erlang-questions mailing list