I'm trying to assign the value of EIP to a C variable but get this error message:

bad register name `%eip'
Here is the code:

        void *ip = 0;
        asm("movl %%eip, %0" : "=r"(ip) );
        printf("Current instruction position: %p\n", ip);
I have managed to get the stack pointer in a similar way without problem, like this:
        void *p = 0;
        asm("movl %%esp, %0"
            : "=r"(p) );

        printf("Stack pointer: %p\n", p);
Any idea what the problem might be?