On 14/10/11 2:13 AM, Pontus Pihlgren wrote:
On Thu, Oct 13, 2011 at 09:14:34PM +0100, Tony Duell
wrote:
for(int
i=0;i<14;i++)
putchar(i["hello world\n"]);
Not very complex, but figuring out how it works i fun :-)
What's to 'work out'? The argument to putchar looks a bit odd, but IIRC,
A[i] is a shorthand for *(A+i), and addition is commutitive (even when it
involves pointers). So that's just indexing an array of chracters (the
string constant) using i.
Hey Tony, cut me some slack. Not all C programmers will recall(or even
know to begin with) that A[i] is shorthand for *(A+1). I learned it
through this example.
Here is another one which also requires some knowledge of standards:
The example *above* doesn't require reading any standards; it's basic C
usage and is in K&R 1. It would be hard to read or write C in any
serious way without having internalised things like this. (Because both
constructs are common.)
What is the safe thing to do after a longjmp to a previous setjmp
position?
iirc, you would avoid using any auto (stack) variables that were in scope.
--Toby
Regards,
Pontus.