1

I am getting the error identifier "character" is undefined. I have included the header file as well and still cannot figure out the reason behind it. The screen shot of the error enter image description here

The print.c file which contains the error

#include "print.h"

const static size_t NUM_COLS = 80;
const static size_t NUM_ROWS = 25;

struct Char
{
    uint8_t character;
    uint8_t color;
};

struct Char *buffer = (struct Char *)0xb8000;
size_t col = 0;
size_t row = 0;
uint8_t color = PRINT_COLOR_WHITE | PRINT_COLOR_BLACK << 4;

void clear_row(size_t row)
{
    struct Char empty = (struct Char){
        character : ' ',
        color : color,
    };

    for (size_t col = 0; col < NUM_COLS; col++)
    {
        buffer[col + NUM_COLS * row] = empty;
    }
}

Other places the character is working fine, For example

void print_char(char character)
{
    if (character == '\n')
    {
        print_newline();
        return;
    }

    if (col > NUM_COLS)
    {
        print_newline();
    }

    buffer[col + NUM_COLS * row] = (struct Char){
        character : (uint8_t)character,
        color : color,
    };

    col++;
}

The header file print.h

#pragma once

#include <stdint.h>
#include <stddef.h>

enum
{
    PRINT_COLOR_BLACK = 0,
    PRINT_COLOR_BLUE = 1,
};

void print_clear();
void print_char(char character);
void print_str(char *string);
void print_set_color(uint8_t foreground, uint8_t background);
Anup Bhattarai
  • 171
  • 1
  • 12
  • 2
    The syntax `color : color,` for designated initializers is an obsolete GNU extension, not standard C. It should be `.color = color,` in standard C. – user17732522 Jan 30 '22 at 01:23

0 Answers0