On Saturday 23 December 2006 10:06, Rask Ingemann Lambertsen wrote:
> No, because you'd read past the end of the array:
>
> #include <stdlib.h>
>
> int main (int argc, char *argv[])
> {
> char *a;
> if ((a == malloc (sizeof (char))))
> {
> int r;
>
> a[0] = 1;
> r = f (a);
> free (a);
> return (r);
> }
> return (0);
> }
Good spotting.
We can use & instead of &&. C standard doesn't
aloow lazy execution of (a & b) IIRC...
int f(char *p)
{
if ((p[0] == 1) & (p[1] == 2)) return 1;
return 0;
}
Currently it does this:
.file "t.c"
.text
.p2align 2,,3
.globl f
.type f, @function
f:
movl 4(%esp), %edx
cmpb $1, (%edx)
sete %al
cmpb $2, 1(%edx)
sete %dl
andl %edx, %eax
movzbl %al, %eax
ret
.size f, .-f
.ident "GCC: (GNU) 4.2.0 20061128 (prerelease)"
.section .note.GNU-stack,"",@progbits
--
vda