Search code examples
xv6

How to print out a pointer using printf under xv6?


I am using xv6 and I want to print out the pointer's address returned from sbrk

I am trying to use: printf(sbrk(0),"%p\n");

But when I tried to make, it complained:

error: passing argument 1 of ‘printf’ makes integer from pointer without a cast [-Werror=int-conversion]
    printf(sbrk(0), "%p\n");

Is there a way to print out a pointer under xv6?

If you want I can share you with the make file - but I just cloned it from the xv6 repo


Solution

  • What about printf(1, "%p\n", sbrk(0));?

    The xv6 printf function (from printf.c) need one extra parameter given first: the fd number in which you want to write.