What is assignment makes pointer from integer without a cast

Programming, for all ages and all languages.
NunoLava1998
Member
Member
Posts: 273
Joined: Sun Oct 09, 2016 4:38 am
Libera.chat IRC: NunoLava1998

What is assignment makes pointer from integer without a cast

Post by NunoLava1998 »

I am putting a lot of functions into my OS (i recently added farpeekl, outb, inb, lidt and kbdhandler).

However, in my keyboard handler, a warning occurs (-Wextra and -Wall):

Code: Select all

kernel.c: In function 'kbdhandler':
kernel.c:199:6: warning: assignment makes pointer from integer without a cast [enabled by default]
  key = kbdus[scancode];
      ^
This is to set the key to the translated scancode-key result.

Here's my kbdus and kbdhandler function, inb and terminal_writestring are exactly as shown in the OSDev wikia. (headers not included):

Code: Select all

unsigned char kbdus[128] =
{
    0,  27, '1', '2', '3', '4', '5', '6', '7', '8',	/* 9 */
  '9', '0', '-', '=', '\b',	/* Backspace */
  '\t',			/* Tab */
  'q', 'w', 'e', 'r',	/* 19 */
  't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n',	/* Enter key */
    0,			/* 29   - Control */
  'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';',	/* 39 */
 '\'', '`',   0,		/* Left shift */
 '\\', 'z', 'x', 'c', 'v', 'b', 'n',			/* 49 */
  'm', ',', '.', '/',   0,				/* Right shift */
  '*',
    0,	/* Alt */
  ' ',	/* Space bar */
    0,	/* Caps lock */
    0,	/* 59 - F1 key ... > */
    0,   0,   0,   0,   0,   0,   0,   0,
    0,	/* < ... F10 */
    0,	/* 69 - Num lock*/
    0,	/* Scroll Lock */
    0,	/* Home key */
    0,	/* Up Arrow */
    0,	/* Page Up */
  '-',
    0,	/* Left Arrow */
    0,
    0,	/* Right Arrow */
  '+',
    0,	/* 79 - End key*/
    0,	/* Down Arrow */
    0,	/* Page Down */
    0,	/* Insert Key */
    0,	/* Delete Key */
    0,   0,   0,
    0,	/* F11 Key */
    0,	/* F12 Key */
    0,	/* All other keys are undefined */
};
void kbdhandler()
{
	unsigned char scancode;
	const char *key;
	scancode = inb(0x60);
	key = kbdus[scancode];
	terminal_writestring(key);
}
It worked fine with putchar but i am switching to writestring since instead of putting the first letter and continuing it filled the screen with whatever the keyboard was sending, which is not what i want.

How do i fix this? I can't seem to find a solution on the internet.
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: What is assignment makes pointer from integer without a

Post by Kevin »

key is a const char* (i.e. a pointer type) whereas kbdus[scancode] is an unsigned char (i.e. an integer type). These are fundamentally different types, so the compiler thinks chances are that the assignment is wrong. And the compiler is right, kbdus[scancode] doesn't contain integers that make sense as a pointer.

If you want a string, you need to create one. That is, you need some memory where you can put the character and a '\0' byte. Maybe in this case a local char array of size 2 is what you want.
Developer of tyndur - community OS of Lowlevel (German)
NunoLava1998
Member
Member
Posts: 273
Joined: Sun Oct 09, 2016 4:38 am
Libera.chat IRC: NunoLava1998

Re: What is assignment makes pointer from integer without a

Post by NunoLava1998 »

Kevin wrote:key is a const char* (i.e. a pointer type) whereas kbdus[scancode] is an unsigned char (i.e. an integer type). These are fundamentally different types, so the compiler thinks chances are that the assignment is wrong. And the compiler is right, kbdus[scancode] doesn't contain integers that make sense as a pointer.

If you want a string, you need to create one. That is, you need some memory where you can put the character and a '\0' byte. Maybe in this case a local char array of size 2 is what you want.
How do i do it? If i try to change kbdus from unsigned char to const char *, this happens:

Code: Select all

kernel.c:46:5: warning: initialization makes pointer from integer without a cast [enabled by default]
     0,  27, '1', '2', '3', '4', '5', '6', '7', '8', /* 9 */
     ^
kernel.c:46:5: warning: (near initialization for 'kbdus[1]') [enabled by default]
kernel.c:46:5: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:46:5: warning: (near initialization for 'kbdus[2]') [enabled by default]
kernel.c:46:5: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:46:5: warning: (near initialization for 'kbdus[3]') [enabled by default]
kernel.c:46:5: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:46:5: warning: (near initialization for 'kbdus[4]') [enabled by default]
kernel.c:46:5: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:46:5: warning: (near initialization for 'kbdus[5]') [enabled by default]
kernel.c:46:5: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:46:5: warning: (near initialization for 'kbdus[6]') [enabled by default]
kernel.c:46:5: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:46:5: warning: (near initialization for 'kbdus[7]') [enabled by default]
kernel.c:46:5: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:46:5: warning: (near initialization for 'kbdus[8]') [enabled by default]
kernel.c:46:5: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:46:5: warning: (near initialization for 'kbdus[9]') [enabled by default]
kernel.c:47:3: warning: initialization makes pointer from integer without a cast [enabled by default]
   '9', '0', '-', '=', '\b', /* Backspace */
   ^
kernel.c:47:3: warning: (near initialization for 'kbdus[10]') [enabled by default]
kernel.c:47:3: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:47:3: warning: (near initialization for 'kbdus[11]') [enabled by default]
kernel.c:47:3: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:47:3: warning: (near initialization for 'kbdus[12]') [enabled by default]
kernel.c:47:3: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:47:3: warning: (near initialization for 'kbdus[13]') [enabled by default]
kernel.c:47:3: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:47:3: warning: (near initialization for 'kbdus[14]') [enabled by default]
kernel.c:48:3: warning: initialization makes pointer from integer without a cast [enabled by default]
   '\t',   /* Tab */
   ^
kernel.c:48:3: warning: (near initialization for 'kbdus[15]') [enabled by default]
kernel.c:49:3: warning: initialization makes pointer from integer without a cast [enabled by default]
   'q', 'w', 'e', 'r', /* 19 */
   ^
kernel.c:49:3: warning: (near initialization for 'kbdus[16]') [enabled by default]
kernel.c:49:3: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:49:3: warning: (near initialization for 'kbdus[17]') [enabled by default]
kernel.c:49:3: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:49:3: warning: (near initialization for 'kbdus[18]') [enabled by default]
kernel.c:49:3: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:49:3: warning: (near initialization for 'kbdus[19]') [enabled by default]
kernel.c:50:3: warning: initialization makes pointer from integer without a cast [enabled by default]
   't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', /* Enter key */
   ^
kernel.c:50:3: warning: (near initialization for 'kbdus[20]') [enabled by default]
kernel.c:50:3: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:50:3: warning: (near initialization for 'kbdus[21]') [enabled by default]
kernel.c:50:3: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:50:3: warning: (near initialization for 'kbdus[22]') [enabled by default]
kernel.c:50:3: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:50:3: warning: (near initialization for 'kbdus[23]') [enabled by default]
kernel.c:50:3: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:50:3: warning: (near initialization for 'kbdus[24]') [enabled by default]
kernel.c:50:3: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:50:3: warning: (near initialization for 'kbdus[25]') [enabled by default]
kernel.c:50:3: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:50:3: warning: (near initialization for 'kbdus[26]') [enabled by default]
kernel.c:50:3: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:50:3: warning: (near initialization for 'kbdus[27]') [enabled by default]
kernel.c:50:3: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:50:3: warning: (near initialization for 'kbdus[28]') [enabled by default]
kernel.c:52:3: warning: initialization makes pointer from integer without a cast [enabled by default]
   'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', /* 39 */
   ^
kernel.c:52:3: warning: (near initialization for 'kbdus[30]') [enabled by default]
kernel.c:52:3: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:52:3: warning: (near initialization for 'kbdus[31]') [enabled by default]
kernel.c:52:3: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:52:3: warning: (near initialization for 'kbdus[32]') [enabled by default]
kernel.c:52:3: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:52:3: warning: (near initialization for 'kbdus[33]') [enabled by default]
kernel.c:52:3: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:52:3: warning: (near initialization for 'kbdus[34]') [enabled by default]
kernel.c:52:3: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:52:3: warning: (near initialization for 'kbdus[35]') [enabled by default]
kernel.c:52:3: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:52:3: warning: (near initialization for 'kbdus[36]') [enabled by default]
kernel.c:52:3: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:52:3: warning: (near initialization for 'kbdus[37]') [enabled by default]
kernel.c:52:3: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:52:3: warning: (near initialization for 'kbdus[38]') [enabled by default]
kernel.c:52:3: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:52:3: warning: (near initialization for 'kbdus[39]') [enabled by default]
kernel.c:53:2: warning: initialization makes pointer from integer without a cast [enabled by default]
  '\'', '`',   0,  /* Left shift */
  ^
kernel.c:53:2: warning: (near initialization for 'kbdus[40]') [enabled by default]
kernel.c:53:2: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:53:2: warning: (near initialization for 'kbdus[41]') [enabled by default]
kernel.c:54:2: warning: initialization makes pointer from integer without a cast [enabled by default]
  '\\', 'z', 'x', 'c', 'v', 'b', 'n',   /* 49 */
  ^
kernel.c:54:2: warning: (near initialization for 'kbdus[43]') [enabled by default]
kernel.c:54:2: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:54:2: warning: (near initialization for 'kbdus[44]') [enabled by default]
kernel.c:54:2: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:54:2: warning: (near initialization for 'kbdus[45]') [enabled by default]
kernel.c:54:2: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:54:2: warning: (near initialization for 'kbdus[46]') [enabled by default]
kernel.c:54:2: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:54:2: warning: (near initialization for 'kbdus[47]') [enabled by default]
kernel.c:54:2: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:54:2: warning: (near initialization for 'kbdus[48]') [enabled by default]
kernel.c:54:2: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:54:2: warning: (near initialization for 'kbdus[49]') [enabled by default]
kernel.c:55:3: warning: initialization makes pointer from integer without a cast [enabled by default]
   'm', ',', '.', '/',   0,    /* Right shift */
   ^
kernel.c:55:3: warning: (near initialization for 'kbdus[50]') [enabled by default]
kernel.c:55:3: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:55:3: warning: (near initialization for 'kbdus[51]') [enabled by default]
kernel.c:55:3: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:55:3: warning: (near initialization for 'kbdus[52]') [enabled by default]
kernel.c:55:3: warning: initialization makes pointer from integer without a cast [enabled by default]
kernel.c:55:3: warning: (near initialization for 'kbdus[53]') [enabled by default]
kernel.c:56:3: warning: initialization makes pointer from integer without a cast [enabled by default]
   '*',
   ^
kernel.c:56:3: warning: (near initialization for 'kbdus[55]') [enabled by default]
kernel.c:58:3: warning: initialization makes pointer from integer without a cast [enabled by default]
   ' ', /* Space bar */
   ^
kernel.c:58:3: warning: (near initialization for 'kbdus[57]') [enabled by default]
kernel.c:68:3: warning: initialization makes pointer from integer without a cast [enabled by default]
   '-',
   ^
kernel.c:68:3: warning: (near initialization for 'kbdus[74]') [enabled by default]
kernel.c:72:3: warning: initialization makes pointer from integer without a cast [enabled by default]
   '+',
   ^
kernel.c:72:3: warning: (near initialization for 'kbdus[78]') [enabled by default]
And terminal_writestring only accepts const char *, so i can't change "key"'s type.
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS
User avatar
Ycep
Member
Member
Posts: 401
Joined: Mon Dec 28, 2015 11:11 am

Re: What is assignment makes pointer from integer without a

Post by Ycep »

Please, learn C already...
This is probably what you wanted:

Code: Select all

void kbdhandler()
{
   unsigned char scancode, key;
   scancode = inb(0x60);
   key = kbdus[scancode];
   terminal_writestring(key);
}
Making mistakes like this one would lead you nowhere in operating system development, as in algorithmic programming, general programming, game programming, etc.
NunoLava1998
Member
Member
Posts: 273
Joined: Sun Oct 09, 2016 4:38 am
Libera.chat IRC: NunoLava1998

Re: What is assignment makes pointer from integer without a

Post by NunoLava1998 »

Lukand wrote:Please, learn C already...
This is probably what you wanted:

Code: Select all

void kbdhandler()
{
   unsigned char scancode, key;
   scancode = inb(0x60);
   key = kbdus[scancode];
   terminal_writestring(key);
}
Making mistakes like this one would lead you nowhere in operating system development, as in algorithmic programming, general programming, game programming, etc.
Except terminal_writestring expects a const char *. Therefore...

Code: Select all

kernel.c: In function 'kbdhandler':
kernel.c:199:4: warning: passing argument 1 of 'terminal_writestring' makes pointer from integer without a cast [enabled by default]
    terminal_writestring(key);
    ^
kernel.c:152:6: note: expected 'const char *' but argument is of type 'unsigned char'
 void terminal_writestring(const char* data) {
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: What is assignment makes pointer from integer without a

Post by iansjack »

Why are you using a string writing function to write a character? Just program a function that writes a single character to the screen.
NunoLava1998
Member
Member
Posts: 273
Joined: Sun Oct 09, 2016 4:38 am
Libera.chat IRC: NunoLava1998

Re: What is assignment makes pointer from integer without a

Post by NunoLava1998 »

iansjack wrote:Why are you using a string writing function to write a character? Just program a function that writes a single character to the screen.
Beacuse terminal_write won't work and terminal_putchar puts the letter that is pressed into every single slot of the screen for some reason.
Also, terminal_writechar with 1 note and 1 warning like you said brings... here, have the bin file, test it on qemu.

here's an image demonstrating what happens if you move your mouse and hold something that keeps the "S " screen
http://i.imgur.com/iS9IUmz.png ((mod edit: Turned oversized image into a link))
Attachments
myos.zip
i don't know how to explain it so try to explain it yourself
(1.43 KiB) Downloaded 62 times
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: What is assignment makes pointer from integer without a

Post by iansjack »

It's kind of you to offer me the chance to debug your code but I'm afraid I must decline the offer.
NunoLava1998
Member
Member
Posts: 273
Joined: Sun Oct 09, 2016 4:38 am
Libera.chat IRC: NunoLava1998

Re: What is assignment makes pointer from integer without a

Post by NunoLava1998 »

iansjack wrote:It's kind of you to offer me the chance to debug your code but I'm afraid I must decline the offer.
It's not to debug my code, it's beacuse i don't know how to explain it so i figured out you could see it.
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: What is assignment makes pointer from integer without a

Post by Solar »

You might want to check the Required Knowledge page in the Wiki. Kernel level programming is a very poor environment to practice your programming skills. You should be proficient in whatever programming language you chose, before you start with OSDev.

User space has much superior debugging tools and features, errors don't require a reboot, examples are easier for others to reproduce, plus several other advantages. There are specialized websites for questions regarding user-space programming, like stackoverflow.com.
Every good solution is obvious once you've found it.
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: What is assignment makes pointer from integer without a

Post by Kevin »

NunoLava1998 wrote:Beacuse terminal_write won't work and terminal_putchar puts the letter that is pressed into every single slot of the screen for some reason.
Then fix that.
How do i do it? If i try to change kbdus from unsigned char to const char *, this happens
This is not what I told you to do.
Developer of tyndur - community OS of Lowlevel (German)
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: What is assignment makes pointer from integer without a

Post by Octacone »

This topic is really scary. How are you expecting your "print string" function to work if your "print character" function is not working... You CANNOT print a character using "print string" function, you need to use "print character" function. I would suggest you fixing your C before fixing anything else
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
onlyonemac
Member
Member
Posts: 1146
Joined: Sat Mar 01, 2014 2:59 pm

Re: What is assignment makes pointer from integer without a

Post by onlyonemac »

Because I don't feel like reading through all your code, I'll answer the question in the thread title:

"assignment makes pointer from integer without a cast" means that you're assigning an integer data type (char, short, int, long) to a variable that's supposed to hold a pointer (void*, char*, any_type_of_your_choice_t*). Sometimes this is a valid operation - say you're calculating a pointer from integer values - but in that case you should cast the value to the correct pointer type. More likely, you've made a mistake and are either a) storing your pointers in integer variables or b) storing your integers in pointer variables. Note that arrays are treated as pointers to the type that they hold, so if you declare an array "int my_array[128]", then my_array is actually a pointer to int (i.e. "int*"), whereas my_array[n] is a value of type int. Also note the difference between "char" and "char*", and between single and double quotes - the former holds a single character while the latter holds an array (string) of characters, and single quotes can be used to specify a single character literal (of type "char") and double quotes to specify a string literal (of type "char*").
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.

Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
NunoLava1998
Member
Member
Posts: 273
Joined: Sun Oct 09, 2016 4:38 am
Libera.chat IRC: NunoLava1998

Re: What is assignment makes pointer from integer without a

Post by NunoLava1998 »

I realized this is beacuse i put the thing in a loop. I tried to implement io_wait and put it in the keyboard_handler, nothin'. I need to know how to halt until a key is pressed.
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS
User avatar
iansjack
Member
Member
Posts: 4685
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: What is assignment makes pointer from integer without a

Post by iansjack »

NunoLava1998 wrote:I need to know how to halt until a key is pressed.
That's why your keyboard handler should be interrupt driven.
Post Reply