How to find the address of a variable when using A

2019-08-01 03:41发布

I am trying to write a program that detects pixel level collision of bitmaps on a Teensy micro controller compiling with AVR-GCC. I am trying to work out how to calculate the position of a single byte of the bitmap on the screen and have been told I should be using pointers. I don't see the relationship between the physical address of a bitmap byte and it's position on the screen, but I would like to investigate. The problem is, I have no way of printing this address. AVR doesn't have printf and I don't know how to get it to display on the screen. Does anyone have a way of producing this address somehow in the terminal?

i.e. if I have a bitmap and want to print out the address of the first byte, what would I need to write to complete this:

??? *bit = &car_bitmap[1]; 
???("%??? ", bit);

2条回答
来,给爷笑一个
2楼-- · 2019-08-01 04:17

Use snprintf and send the string to the terminal. It is very costly on the AVR uC. If you use gcc address spaces extensions you may have to link the support for the long numbers.

查看更多
手持菜刀,她持情操
3楼-- · 2019-08-01 04:20

Assuming you have a working printf(), this should work:

void * const bit = &car_bitmap[1]; 
printf("%p\n", bit);

Where %p is how to print a void *. Other pointer types should be cast to void * in order to match, but I used a void * for the address into the framebuffer anyway.

查看更多
登录 后发表回答