OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 1:40 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 24 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: What is assignment makes pointer from integer without a cast
PostPosted: Wed Dec 07, 2016 4:40 am 
Offline
Member
Member

Joined: Sun Oct 09, 2016 4:38 am
Posts: 273
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:
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:
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


Top
 Profile  
 
 Post subject: Re: What is assignment makes pointer from integer without a
PostPosted: Wed Dec 07, 2016 4:53 am 
Offline
Member
Member

Joined: Sun Feb 01, 2009 6:11 am
Posts: 1070
Location: Germany
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)


Top
 Profile  
 
 Post subject: Re: What is assignment makes pointer from integer without a
PostPosted: Wed Dec 07, 2016 4:59 am 
Offline
Member
Member

Joined: Sun Oct 09, 2016 4:38 am
Posts: 273
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:
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


Top
 Profile  
 
 Post subject: Re: What is assignment makes pointer from integer without a
PostPosted: Wed Dec 07, 2016 5:14 am 
Offline
Member
Member
User avatar

Joined: Mon Dec 28, 2015 11:11 am
Posts: 401
Please, learn C already...
This is probably what you wanted:
Code:
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.


Top
 Profile  
 
 Post subject: Re: What is assignment makes pointer from integer without a
PostPosted: Wed Dec 07, 2016 5:25 am 
Offline
Member
Member

Joined: Sun Oct 09, 2016 4:38 am
Posts: 273
Lukand wrote:
Please, learn C already...
This is probably what you wanted:
Code:
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:
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


Top
 Profile  
 
 Post subject: Re: What is assignment makes pointer from integer without a
PostPosted: Wed Dec 07, 2016 5:44 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
Why are you using a string writing function to write a character? Just program a function that writes a single character to the screen.


Top
 Profile  
 
 Post subject: Re: What is assignment makes pointer from integer without a
PostPosted: Wed Dec 07, 2016 6:29 am 
Offline
Member
Member

Joined: Sun Oct 09, 2016 4:38 am
Posts: 273
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:
File comment: i don't know how to explain it so try to explain it yourself
myos.zip [1.43 KiB]
Downloaded 29 times

_________________
Developing TRIODIUM OS. Or call it Dixium if you want. It doesn't matter.

https://github.com/NunoLava1998/DixiumOS
Top
 Profile  
 
 Post subject: Re: What is assignment makes pointer from integer without a
PostPosted: Wed Dec 07, 2016 6:38 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
It's kind of you to offer me the chance to debug your code but I'm afraid I must decline the offer.


Top
 Profile  
 
 Post subject: Re: What is assignment makes pointer from integer without a
PostPosted: Wed Dec 07, 2016 6:46 am 
Offline
Member
Member

Joined: Sun Oct 09, 2016 4:38 am
Posts: 273
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


Top
 Profile  
 
 Post subject: Re: What is assignment makes pointer from integer without a
PostPosted: Wed Dec 07, 2016 7:16 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7614
Location: Germany
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.


Top
 Profile  
 
 Post subject: Re: What is assignment makes pointer from integer without a
PostPosted: Wed Dec 07, 2016 7:59 am 
Offline
Member
Member

Joined: Sun Feb 01, 2009 6:11 am
Posts: 1070
Location: Germany
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.

Quote:
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)


Top
 Profile  
 
 Post subject: Re: What is assignment makes pointer from integer without a
PostPosted: Wed Dec 07, 2016 11:22 pm 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
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


Top
 Profile  
 
 Post subject: Re: What is assignment makes pointer from integer without a
PostPosted: Thu Dec 08, 2016 2:25 am 
Offline
Member
Member

Joined: Sat Mar 01, 2014 2:59 pm
Posts: 1146
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


Top
 Profile  
 
 Post subject: Re: What is assignment makes pointer from integer without a
PostPosted: Thu Dec 08, 2016 5:37 am 
Offline
Member
Member

Joined: Sun Oct 09, 2016 4:38 am
Posts: 273
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


Top
 Profile  
 
 Post subject: Re: What is assignment makes pointer from integer without a
PostPosted: Thu Dec 08, 2016 5:51 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
NunoLava1998 wrote:
I need to know how to halt until a key is pressed.
That's why your keyboard handler should be interrupt driven.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 24 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 87 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group