L
linzhenhua1205
I occur a oddity C program,when I surfed the Internet. I have
confussed by the style. Who can show detail information about it?
<code> (original)
int i;main(){for(;i["]<i;++i){--i;}"];read('-'-'-',i+++"hell\
o, world!\n",'/'/'/'));}read(j,i,p){write(j/p+p,i---j,i/i);}
</code>
And I cut down some of it.And the code is like following.
<code> (modified)
int i;
read(i)
{
write(1,i--,i/i);
}
main()
{
for(; i["]<i;++i){--i;}"]; read(i+++"hello, world!\n"))
;
}
</code>
And now my problem is that
1.How does for statement check the condition?
2.Why the variable "i" can use like array at the first position in the
second expression (In the for loops)? Directly, what does the string--
i["]<i;++i){--i;}"]; -- mean?
3.How does the read function pass argument?
The following information maybe have some help:
1.The assembly code generates by the gcc -s
<code>
.file "Test.c"
.text
..globl _read
.def _read; .scl 2; .type 32; .endef
_read:
pushl %ebp
movl %esp, %ebp
subl $24, %esp
movl 8(%ebp), %eax
cltd
idivl 8(%ebp)
movl %eax, 8(%esp)
movl 8(%ebp), %eax
movl %eax, 4(%esp)
decl 8(%ebp)
movl $1, (%esp)
call _write
leave
ret
.def ___main; .scl 2; .type 32; .endef
LC0:
.ascii "]<i;++i){--i;}\0"
LC1:
.ascii "hello, world!\12\0"
..globl _main
.def _main; .scl 2; .type 32; .endef
_main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
andl $-16, %esp
movl $0, %eax
movl %eax, -4(%ebp)
movl -4(%ebp), %eax
call __alloca
call ___main
L3:
movl _i, %eax
addl $LC0, %eax
cmpb $0, (%eax)
jne L5
jmp L4
L5:
movl _i, %eax
addl $LC1, %eax
movl %eax, (%esp)
incl _i
call _read
jmp L3
L4:
leave
ret
.comm _i, 16 # 4
.def _write; .scl 2; .type 32; .endef
</code>
confussed by the style. Who can show detail information about it?
<code> (original)
int i;main(){for(;i["]<i;++i){--i;}"];read('-'-'-',i+++"hell\
o, world!\n",'/'/'/'));}read(j,i,p){write(j/p+p,i---j,i/i);}
</code>
And I cut down some of it.And the code is like following.
<code> (modified)
int i;
read(i)
{
write(1,i--,i/i);
}
main()
{
for(; i["]<i;++i){--i;}"]; read(i+++"hello, world!\n"))
;
}
</code>
And now my problem is that
1.How does for statement check the condition?
2.Why the variable "i" can use like array at the first position in the
second expression (In the for loops)? Directly, what does the string--
i["]<i;++i){--i;}"]; -- mean?
3.How does the read function pass argument?
The following information maybe have some help:
1.The assembly code generates by the gcc -s
<code>
.file "Test.c"
.text
..globl _read
.def _read; .scl 2; .type 32; .endef
_read:
pushl %ebp
movl %esp, %ebp
subl $24, %esp
movl 8(%ebp), %eax
cltd
idivl 8(%ebp)
movl %eax, 8(%esp)
movl 8(%ebp), %eax
movl %eax, 4(%esp)
decl 8(%ebp)
movl $1, (%esp)
call _write
leave
ret
.def ___main; .scl 2; .type 32; .endef
LC0:
.ascii "]<i;++i){--i;}\0"
LC1:
.ascii "hello, world!\12\0"
..globl _main
.def _main; .scl 2; .type 32; .endef
_main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
andl $-16, %esp
movl $0, %eax
movl %eax, -4(%ebp)
movl -4(%ebp), %eax
call __alloca
call ___main
L3:
movl _i, %eax
addl $LC0, %eax
cmpb $0, (%eax)
jne L5
jmp L4
L5:
movl _i, %eax
addl $LC1, %eax
movl %eax, (%esp)
incl _i
call _read
jmp L3
L4:
leave
ret
.comm _i, 16 # 4
.def _write; .scl 2; .type 32; .endef
</code>