Compiling my own kernel (not from linux-kernel source)

I follow the kernel guide from here

im has problems compiling my files.

I get the following errors when I try to compile:

main.c:8: error: expected declaration specifiers or ‘...’ before ‘size_t
main.c:8: error: conflicting types formemcpy
./include/system.h:5: note: previous declaration of ‘memcpy’ was here    
main.c: In function ‘memcpy’:                                            
main.c:12: error: ‘count’ undeclared (first use in this function)        
main.c:12: error: (Each undeclared identifier is reported only once      
main.c:12: error: for each function it appears in.)                      
main.c: At top level:                                                    
main.c:16: error: expected declaration specifiers or ‘...’ before ‘size_t
main.c:16: error: conflicting types formemset
./include/system.h:6: note: previous declaration of ‘memset’ was here
main.c: In function ‘memset’:
main.c:19: error: ‘count’ undeclared (first use in this function)
main.c: At top level:
main.c:23: error: expected declaration specifiers or ‘...’ before ‘size_t
main.c:23: error: conflicting types for ‘memsetw’
./include/system.h:7: note: previous declaration of ‘memsetw’ was here
main.c: In function ‘memsetw’:
main.c:26: error: ‘count’ undeclared (first use in this function)
main.c: At top level:
main.c:30: error: expected ‘=’, ‘,’, ‘;’, ‘asmor ‘__attribute__’ before ‘strlen
main.c:49: warning: return type of ‘main’ is notint
main.c: In function ‘main’:
main.c:64: warning: pointer targets in passing argument 1 of ‘puts’ differ in    signedness
./include/system.h:13: note: expected ‘unsigned char *’ but argument is of type ‘char *’
main.c:51: warning: unused variable ‘i’
scrn.c: In function ‘scroll’:
scrn.c:24: warning: passing argument 1 of ‘memcpy’ from incompatible pointer type
./include/system.h:5: note: expected ‘unsigned char *’ but argument is of type ‘short unsigned int *’
scrn.c:24: warning: passing argument 2 of ‘memcpy’ from incompatible pointer type
./include/system.h:5: note: expected ‘const unsigned char *’ but argument is of type  ‘short unsigned int *’
scrn.c: In function ‘puts’:
scrn.c:139: warning: pointer targets in passing argument 1 of ‘strlen’ differ in signedness
./include/system.h:8: note: expected ‘const char *’ but argument is of type ‘unsigned char *’

My files are exact copies of those from the textbook.
I see that in main.c the functions are defined like this

void *memcpy(void *dest,const void *src, size_t count)

but in my system.h file they are defined like this

extern unsigned char *memcpy(unsigned char *dest,const unsigned char *src, int count)

C is not my main language, but I'm learning it, so I apologize if my question is simple, but I think these definitions should be the same?

+3
source share
2 answers

, , size_t int , size_t . ( , sizeof(char*) == sizeof(void*)).

, system.h. system.h, main.c, , . , , C memcpy :

unsigned char *memcpy(unsigned char *dest, const unsigned char *src, int count);

, , :

void *memcpy(void *dest, const void *src, size_t count);

:

/* bkerndev - Bran Kernel Development Tutorial
*  By:   Brandon F. (friesenb@gmail.com)
*  Desc: Main.c: C code entry.
*
*  Notes: No warranty expressed or implied. Use at own risk. */

, , . , . , , ... , , - .

+5

size_t int main.c

-1

Source: https://habr.com/ru/post/1722127/


All Articles