-1

I'm trying to print an 'A' by my kernel, but there is a big problem.

First, I have a array which is named "font_A"

static unsigned char font_A[16] = {
    0x00,0x18,0x18,0x18,0x18,0x24,0x24,0x24,0x24,0x7e,0x42,0x42,0x42,0xe7,0x00,0x00
};

This code can not print anything

unsigned char data;
for (int i = 0; i < 16; i++) {
    data = *(font_A + i);
    for (int j = 0; j < 8; j++) {
        if (data & (0x80 >> j)) {
            draw_pixel(frameBuffer, 0x00ffffff, 100 + j, 100 + i);
        }
    }
}

But, when I delete the for loop, like this:

    unsigned char data;
    int i = 0;

    data = *(font_A + i);
    for (int j = 0; j < 8; j++) {
        if (data & (0x80 >> j)) {
            draw_pixel(frameBuffer, 0x00ffffff, 100 + j, 100 + i);
        }
    }
    i++;
    data = *(font_A + i);
    for (int j = 0; j < 8; j++) {
        if (data & (0x80 >> j)) {
            draw_pixel(frameBuffer, 0x00ffffff, 100 + j, 100 + i);
        }
    }
    i++;
    //...16 times in total

It printed 'A' successfully.

But why? And how I can use loop correctly?

  • ` data = *(font_A + i);` why not just `font+A[i]`? – Pepijn Kramer Aug 12 '23 at 15:31
  • Both OK, I just want to know why I can not use loop. I've tried while and for in the past few minutes, but both of them do not work. – OrderChaos Aug 12 '23 at 15:41
  • I don't see what's going on. But I have something that may interest you. Part of your bitmasking work can be moved to compile time. Example : https://onlinegdb.com/gSes_gnD9 and in that example I can use a loop just fine... – Pepijn Kramer Aug 12 '23 at 15:53
  • Can we see the `draw_pixel` function? – xingharvey Aug 13 '23 at 19:23
  • Things are going confusing. clang++ can compile my codes perfectly, and output program is good. But g++ can not, it will show nothing – OrderChaos Aug 18 '23 at 07:21

0 Answers0