Mailing List Archive
tlug.jp Mailing List tlug archive tlug Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]Re: [tlug] C puzzle
- Date: 30 Jul 2002 22:09:11 +0900
- From: bruno raoult <br@example.com>
- Subject: Re: [tlug] C puzzle
- References: <20020726012006.M48242-100000@example.com> <15680.11598.642676.889439@example.com> <1027725222.13382.6.camel@example.com> <m3d6t6xcn8.wl@example.com co.jp> <15685.61809.707516.99320@example.com> <3D45F5AD.7030707@example.com>
Exactly, it looks correct to me: If I want to get the smallest C program to crash, it would certainly not be "correct" in some manner, but this is what I wish! It is probably more correct than a "correct" program which crashes when it should not :-) It means we got 2 solutions for this 1-char output problem :-) br. PS. BTW, what is this "smallest C program", which compiles with no options? On Tue, 2002-07-30 at 11:10, Josh Glover wrote: > > I don't think this one satisfies the original request to turn the > > sample into a "correct C program". The original code is much more > > correct than your solution:) > > No, my friend. Whether C is "correct" or not is dependent on only one > thing: compiling and doing what it is supposed to. Macho C hackers > cackle with glee over this clever use of pointer arithmatic. :) > > > Nevertheless it works (despite of gcc complaints). I think it's > > because the pointer to int is unsigned, so negating it results in a > > big positive number. > > You would seem to be right: > > (gdb) l > 1 > 2 main() { > 3 int*i, n=20; > 4 for(i = 0 ; i < n ; i--) > 5 printf("-"); > 6 } > (gdb) b 3 > Breakpoint 1 at 0x8048466: file test.c, line 3. > (gdb) r > Starting program: /home/jmglov/test > > Breakpoint 1, main () at test.c:3 > 3 int*i, n=20; > (gdb) n > 4 for(i = 0 ; i < n ; i--) > (gdb) p i > $1 = (int *) 0x804961c > (gdb) n > 5 printf("-"); > (gdb) p i > $2 = (int *) 0x0 > (gdb) p n > $3 = 20 > (gdb) p i < n > $4 = 1 > (gdb) n > 4 for(i = 0 ; i < n ; i--) > (gdb) p i > $5 = (int *) 0x0 > (gdb) n > 6 } > (gdb) p i > $6 = (int *) 0xfffffffc > (gdb) p i < n > $7 = 0 -- Any sufficiently advanced bug is indistinguishable from a feature. -- Rich KulawiecAttachment: signature.asc
Description: This is a digitally signed message part
- Follow-Ups:
- Re: [tlug] C puzzle
- From: Josh Glover
- References:
- [tlug] C puzzle
- From: Tod McQuillin
- Re: [tlug] C puzzle
- From: Viktor Pavlenko
- Re: [tlug] C puzzle
- From: bruno raoult
- Re: [tlug] C puzzle
- From: Viktor Pavlenko
- Re: [tlug] C puzzle
- From: Josh Glover
Home | Main Index | Thread Index
- Prev by Date: [tlug] Linux for Beginners
- Next by Date: Re: [tlug] C puzzle
- Previous by thread: Re: [tlug] C puzzle
- Next by thread: Re: [tlug] C puzzle
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links