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

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

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:
Code:
        void *p = 0;
        asm("movl %%esp, %0"
            : "=r"(p) );

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