As I'm new to lexer and parser, so I'm trying to read and understand others code.
Here is the code i'm trying to use : https://gist.github.com/justjkk/436828
But it's giving me error. How can I resolve this?
E:\flex_bison_test>gcc lex.yy.c y.tab.c -o json.exe
json.l: In function 'yylex':
json.l:34:11: warning: assignment to 'YYSTYPE' {aka 'int'} from 'char *' makes integer from pointer without a cast [-Wint-conversion]
yylval=strclone(yytext);
^
json.l:38:11: warning: assignment to 'YYSTYPE' {aka 'int'} from 'char *' makes integer from pointer without a cast [-Wint-conversion]
yylval=strclone(yytext);
^
json.l: In function 'strclone':
json.l:82:15: warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration]
int len = strlen(str);
^~~~~~
json.l:82:15: warning: incompatible implicit declaration of built-in function 'strlen'
json.l:82:15: note: include '<string.h>' or provide a declaration of 'strlen'
json.l:79:1:
+#include <string.h>
%%
json.l:82:15:
int len = strlen(str);
^~~~~~
json.l:84:5: warning: implicit declaration of function 'strcpy' [-Wimplicit-function-declaration]
strcpy(clone,str);
^~~~~~
json.l:84:5: warning: incompatible implicit declaration of built-in function 'strcpy'
json.l:84:5: note: include '<string.h>' or provide a declaration of 'strcpy'
y.tab.c: In function 'yyparse':
y.tab.c:627:16: warning: implicit declaration of function 'yylex' [-Wimplicit-function-declaration]
# define YYLEX yylex ()
^~~~~
y.tab.c:1272:16: note: in expansion of macro 'YYLEX'
yychar = YYLEX;
^~~~~
y.tab.c:1540:7: warning: implicit declaration of function 'yyerror'; did you mean 'yyerrok'? [-Wimplicit-function-declaration]
yyerror (YY_("syntax error"));
^~~~~~~
yyerrok
json.y: At top level:
json.y:80:6: warning: conflicting types for 'yyerror'
void yyerror (char const *s) {
^~~~~~~
y.tab.c:1540:7: note: previous implicit declaration of 'yyerror' was here
yyerror (YY_("syntax error"));
^~~~~~~
E:\flex_bison_test>
Or these should remain as it is.
All the commands, I have given :
flex json.l
bison -dy json.y
gcc lex.yy.c y.tab.c -o json.exe
Simply:
#include <string.h>
in your flex definitions section on top of json.l should fix it for you.
There's also a Makefile in the repository you pointed to. Maybe you should use that. You don't seem to be generating the parser files properly. See comment below.
As for the remaining warnings:
warning: implicit declaration of function 'yyerror';
warning: implicit declaration of function 'yylex';
These can be easily fixed by adding declarations of yylex() and yyerror should be present in the bison prologue section at the top of your json.y:
%{
int yylex();
void yyerror(const char *s);
%}
As for these ones:
json.l:34:11: warning: assignment to 'YYSTYPE' {aka 'int'} from 'char *' makes integer from pointer without a cast [-Wint-conversion]
yylval=strclone(yytext);
^
json.l:38:11: warning: assignment to 'YYSTYPE' {aka 'int'} from 'char *' makes integer from pointer without a cast [-Wint-conversion]
yylval=strclone(yytext);
^
They're a bit more subtle. I would suggest have a look here on how to use yylval for correctly passing on strings from the lex's tokens into the parser's actions. The problem now is that yylval is a bare int but it ends up being assigned char pointers for both NUMBER and STRING tokens.
I am trying to compile a simple program written in c on my new desktop. It installed completely normally without any error on my older machine but for some reason it is giving me lots of compilation warnings when I am trying to compile it here. I installed gcc, g++, xpm and xlib which are the pre requisites of this program. Could it be that I am missing some library or something on my new machine?
Here are the warnings I get:
gcc -o view_qsfr qsfr_2005a_tool_box.c -lX11 -lm -lc -L/usr/X11R6/lib -lXpm
In file included from qsfr_2005a_tool_box.c:44:0:
qsfr_2005a_readQSFR.c: In function ‘Read_QSFR’:
qsfr_2005a_readQSFR.c:706:19: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[201]’ [-Wformat=]
scanf("%s",&fname_extra);
^
In file included from qsfr_2005a_graphics.c:8:0,
from qsfr_2005a_tool_box.c:45:
rotated.c: In function ‘XRotPaintAlignedString’:
rotated.c:450:9: warning: return makes integer from pointer without a cast [-Wint-conversion]
return NULL;
^
rotated.c:453:36: warning: passing argument 3 of ‘XCreateGC’ makes integer from pointer without a cast [-Wint-conversion]
my_gc=XCreateGC(dpy, drawable, NULL, 0);
^
In file included from qsfr_2005a_graphics.c:7:0,
from qsfr_2005a_tool_box.c:45:
/usr/include/X11/Xlib.h:1584:11: note: expected ‘long unsigned int’ but argument is of type ‘void *’
extern GC XCreateGC(
^
In file included from qsfr_2005a_graphics.c:8:0,
from qsfr_2005a_tool_box.c:45:
rotated.c:510:45: warning: passing argument 3 of ‘XCreateGC’ makes integer from pointer without a cast [-Wint-conversion]
depth_one_gc=XCreateGC(dpy, empty_stipple, NULL, 0);
^
In file included from qsfr_2005a_graphics.c:7:0,
from qsfr_2005a_tool_box.c:45:
/usr/include/X11/Xlib.h:1584:11: note: expected ‘long unsigned int’ but argument is of type ‘void *’
extern GC XCreateGC(
^
In file included from qsfr_2005a_graphics.c:8:0,
from qsfr_2005a_tool_box.c:45:
rotated.c:566:43: warning: passing argument 3 of ‘XCreateGC’ makes integer from pointer without a cast [-Wint-conversion]
depth_one_gc=XCreateGC(dpy, new_bitmap, NULL, 0);
^
In file included from qsfr_2005a_graphics.c:7:0,
from qsfr_2005a_tool_box.c:45:
/usr/include/X11/Xlib.h:1584:11: note: expected ‘long unsigned int’ but argument is of type ‘void *’
extern GC XCreateGC(
^
In file included from qsfr_2005a_graphics.c:8:0,
from qsfr_2005a_tool_box.c:45:
rotated.c: In function ‘XRotDrawHorizontalString’:
rotated.c:670:36: warning: passing argument 3 of ‘XCreateGC’ makes integer from pointer without a cast [-Wint-conversion]
my_gc=XCreateGC(dpy, drawable, NULL, 0);
^
In file included from qsfr_2005a_graphics.c:7:0,
from qsfr_2005a_tool_box.c:45:
/usr/include/X11/Xlib.h:1584:11: note: expected ‘long unsigned int’ but argument is of type ‘void *’
extern GC XCreateGC(
^
In file included from qsfr_2005a_graphics.c:8:0,
from qsfr_2005a_tool_box.c:45:
rotated.c: In function ‘XRotCreateTextItem’:
rotated.c:982:36: warning: passing argument 3 of ‘XCreateGC’ makes integer from pointer without a cast [-Wint-conversion]
font_gc=XCreateGC(dpy, canvas, NULL, 0);
^
In file included from qsfr_2005a_graphics.c:7:0,
from qsfr_2005a_tool_box.c:45:
/usr/include/X11/Xlib.h:1584:11: note: expected ‘long unsigned int’ but argument is of type ‘void *’
extern GC XCreateGC(
^
In file included from qsfr_2005a_graphics.c:8:0,
from qsfr_2005a_tool_box.c:45:
rotated.c: In function ‘XRotAddToLinkedList’:
rotated.c:1240:18: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 4 has type ‘int’ [-Wformat=]
DEBUG_PRINT4("current cache size=%ld, new item=%ld, limit=%ld\n",
^
rotated.c:66:53: note: in definition of macro ‘DEBUG_PRINT4’
#define DEBUG_PRINT4(a, b, c, d) if (debug) printf (a, b, c, d)
^
rotated.c:1253:15: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long int’ [-Wformat=]
DEBUG_PRINT2("Removed %d bytes\n", i1->size);
^
rotated.c:64:47: note: in definition of macro ‘DEBUG_PRINT2’
#define DEBUG_PRINT2(a, b) if (debug) printf (a, b)
^
In file included from qsfr_2005a_tool_box.c:45:0:
qsfr_2005a_graphics.c: In function ‘initX’:
qsfr_2005a_graphics.c:48:27: warning: passing argument 3 of ‘XCreateGC’ makes integer from pointer without a cast [-Wint-conversion]
gc=XCreateGC(display,win,NULL,NULL);
^
In file included from qsfr_2005a_graphics.c:7:0,
from qsfr_2005a_tool_box.c:45:
/usr/include/X11/Xlib.h:1584:11: note: expected ‘long unsigned int’ but argument is of type ‘void *’
extern GC XCreateGC(
^
In file included from qsfr_2005a_tool_box.c:45:0:
qsfr_2005a_graphics.c: In function ‘Plot_Correlation_Matrix’:
qsfr_2005a_graphics.c:748:10: warning: implicit declaration of function ‘XpmWriteFileFromPixmap’ [-Wimplicit-function-declaration]
XpmWriteFileFromPixmap(display, fname_out, pix, 0, NULL);
^
qsfr_2005a_tool_box.c: At top level:
qsfr_2005a_tool_box.c:413:4: warning: return type defaults to ‘int’ [-Wimplicit-int]
main(int argc, char **argv)
^
physics#XPHYS9G7XGC2LLT:~/Desktop/viewQSFR/viewQSFR$ sudo make
gcc -o view_qsfr qsfr_2005a_tool_box.c -lX11 -lm -lc -L/usr/X11R6/lib -lXpm
In file included from qsfr_2005a_tool_box.c:44:0:
qsfr_2005a_readQSFR.c: In function ‘Read_QSFR’:
qsfr_2005a_readQSFR.c:706:19: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[201]’ [-Wformat=]
scanf("%s",&fname_extra);
^
In file included from qsfr_2005a_graphics.c:8:0,
from qsfr_2005a_tool_box.c:45:
rotated.c: In function ‘XRotPaintAlignedString’:
rotated.c:450:9: warning: return makes integer from pointer without a cast [-Wint-conversion]
return NULL;
^
rotated.c:453:36: warning: passing argument 3 of ‘XCreateGC’ makes integer from pointer without a cast [-Wint-conversion]
my_gc=XCreateGC(dpy, drawable, NULL, 0);
^
In file included from qsfr_2005a_graphics.c:7:0,
from qsfr_2005a_tool_box.c:45:
/usr/include/X11/Xlib.h:1584:11: note: expected ‘long unsigned int’ but argument is of type ‘void *’
extern GC XCreateGC(
^
In file included from qsfr_2005a_graphics.c:8:0,
from qsfr_2005a_tool_box.c:45:
rotated.c:510:45: warning: passing argument 3 of ‘XCreateGC’ makes integer from pointer without a cast [-Wint-conversion]
depth_one_gc=XCreateGC(dpy, empty_stipple, NULL, 0);
^
In file included from qsfr_2005a_graphics.c:7:0,
from qsfr_2005a_tool_box.c:45:
/usr/include/X11/Xlib.h:1584:11: note: expected ‘long unsigned int’ but argument is of type ‘void *’
extern GC XCreateGC(
^
In file included from qsfr_2005a_graphics.c:8:0,
from qsfr_2005a_tool_box.c:45:
rotated.c:566:43: warning: passing argument 3 of ‘XCreateGC’ makes integer from pointer without a cast [-Wint-conversion]
depth_one_gc=XCreateGC(dpy, new_bitmap, NULL, 0);
^
In file included from qsfr_2005a_graphics.c:7:0,
from qsfr_2005a_tool_box.c:45:
/usr/include/X11/Xlib.h:1584:11: note: expected ‘long unsigned int’ but argument is of type ‘void *’
extern GC XCreateGC(
^
In file included from qsfr_2005a_graphics.c:8:0,
from qsfr_2005a_tool_box.c:45:
rotated.c: In function ‘XRotDrawHorizontalString’:
rotated.c:670:36: warning: passing argument 3 of ‘XCreateGC’ makes integer from pointer without a cast [-Wint-conversion]
my_gc=XCreateGC(dpy, drawable, NULL, 0);
^
In file included from qsfr_2005a_graphics.c:7:0,
from qsfr_2005a_tool_box.c:45:
/usr/include/X11/Xlib.h:1584:11: note: expected ‘long unsigned int’ but argument is of type ‘void *’
extern GC XCreateGC(
^
In file included from qsfr_2005a_graphics.c:8:0,
from qsfr_2005a_tool_box.c:45:
rotated.c: In function ‘XRotCreateTextItem’:
rotated.c:982:36: warning: passing argument 3 of ‘XCreateGC’ makes integer from pointer without a cast [-Wint-conversion]
font_gc=XCreateGC(dpy, canvas, NULL, 0);
^
In file included from qsfr_2005a_graphics.c:7:0,
from qsfr_2005a_tool_box.c:45:
/usr/include/X11/Xlib.h:1584:11: note: expected ‘long unsigned int’ but argument is of type ‘void *’
extern GC XCreateGC(
^
In file included from qsfr_2005a_graphics.c:8:0,
from qsfr_2005a_tool_box.c:45:
rotated.c: In function ‘XRotAddToLinkedList’:
rotated.c:1240:18: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 4 has type ‘int’ [-Wformat=]
DEBUG_PRINT4("current cache size=%ld, new item=%ld, limit=%ld\n",
^
rotated.c:66:53: note: in definition of macro ‘DEBUG_PRINT4’
#define DEBUG_PRINT4(a, b, c, d) if (debug) printf (a, b, c, d)
^
rotated.c:1253:15: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long int’ [-Wformat=]
DEBUG_PRINT2("Removed %d bytes\n", i1->size);
^
rotated.c:64:47: note: in definition of macro ‘DEBUG_PRINT2’
#define DEBUG_PRINT2(a, b) if (debug) printf (a, b)
^
In file included from qsfr_2005a_tool_box.c:45:0:
qsfr_2005a_graphics.c: In function ‘initX’:
qsfr_2005a_graphics.c:48:27: warning: passing argument 3 of ‘XCreateGC’ makes integer from pointer without a cast [-Wint-conversion]
gc=XCreateGC(display,win,NULL,NULL);
^
In file included from qsfr_2005a_graphics.c:7:0,
from qsfr_2005a_tool_box.c:45:
/usr/include/X11/Xlib.h:1584:11: note: expected ‘long unsigned int’ but argument is of type ‘void *’
extern GC XCreateGC(
^
In file included from qsfr_2005a_tool_box.c:45:0:
qsfr_2005a_graphics.c: In function ‘Plot_Correlation_Matrix’:
qsfr_2005a_graphics.c:748:10: warning: implicit declaration of function ‘XpmWriteFileFromPixmap’ [-Wimplicit-function-declaration]
XpmWriteFileFromPixmap(display, fname_out, pix, 0, NULL);
^
qsfr_2005a_tool_box.c: At top level:
qsfr_2005a_tool_box.c:413:4: warning: return type defaults to ‘int’ [-Wimplicit-int]
main(int argc, char **argv)
Unless you are using the -Werror flag to turn warnings into errors then the compiler will still have produced an executable that you can run.
The warnings are probably due to the fact that your new system has a newer compiler that is better at detecting problems in your code.
My suggestion would be to fix the warnings if you can/have time. Otherwise just run the program and ignore the warnings (for now, but fix them eventually).
Is your new computer 64 bit?
Is your older computer 32 bit?
The types of warnings I see suggest that you have 32 bit code that you might be trying to compile on a 64 bit computer (as well as the compiler being a much newer version).
I'm trying to write an MPI worker in C that will communicate with the MPI master, written in python. The master will send out scatters and gathers, and the C worker should receive those and return variables via gather. The problem is, I'm having trouble successfully writing the worker file.
(The reason the worker is in C is because this code is a skeleton to wrap around preexisting python and C programs.)
Here is the code I've written:
#include <stdio.h>
#include <mpi.h>
MPI_Comm comm;
MPI_Comm_get_parent(&comm);
int myid, world_size, size;
int root = 0;
int* endloop = malloc(sizeof(int));
int nelements1 = 1E3;
int nelements2 = 1E6;
float* input = malloc(sizeof(float) * nelements1);
float output[nelements2];
int randomarray(){
float array[nelements2];
srand(time(NULL));
for( i = 0; i < nelements2; i++ ){
array[i] = rand() % 0 + 1E6;
}
return array;
MPI_Comm_rank(MPI_COMM_WORLD, &myid);
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
MPI_Comm_remote_size(comm, &size);
output = randomarray();
MPI_Scatter(endloop, 1, MPI_INT, root, comm);
while ( endloop[0] < 1) {
MPI_Barrier(comm);
MPI_Scatter(input, nelements1, MPI_FLOAT, root, comm);
MPI_Barrier(comm);
MPI_Gather(output, nelements2, MPI_FLOAT, root, comm);
MPI_Scatter(endloop, 1, MPI_INT, root, comm);
}
MPI_Finalize();
And the error output when I attempt to compile is:
maddie#exo:~/code/bart_commloop$ mpicc worker.c -o worker
worker.c:5:21: error: expected declaration specifiers or ‘...’ before ‘&’ token
worker.c:9:16: warning: incompatible implicit declaration of built-in function ‘malloc’ [enabled by default]
worker.c:9:1: error: initializer element is not constant
worker.c:12:1: error: initializer element is not constant
worker.c:13:7: error: variably modified ‘output’ at file scope
worker.c: In function ‘randomarray’:
worker.c:18:7: error: ‘i’ undeclared (first use in this function)
worker.c:18:7: note: each undeclared identifier is reported only once for each function it appears in
worker.c:19:21: warning: division by zero [-Wdiv-by-zero]
worker.c:22:2: warning: return makes integer from pointer without a cast [enabled by default]
worker.c:22:2: warning: function returns address of local variable [enabled by default]
worker.c:28:8: error: incompatible types when assigning to type ‘float[1]’ from type ‘int’
worker.c:30:1: warning: passing argument 4 of ‘MPI_Scatter’ makes pointer from integer without a cast [enabled by default]
/usr/lib/openmpi/include/mpi.h:1197:20: note: expected ‘void *’ but argument is of type ‘int’
worker.c:30:1: warning: passing argument 5 of ‘MPI_Scatter’ makes integer from pointer without a cast [enabled by default]
/usr/lib/openmpi/include/mpi.h:1197:20: note: expected ‘int’ but argument is of type ‘MPI_Comm’
worker.c:30:1: error: too few arguments to function ‘MPI_Scatter’
/usr/lib/openmpi/include/mpi.h:1197:20: note: declared here
worker.c:34:2: warning: passing argument 4 of ‘MPI_Scatter’ makes pointer from integer without a cast [enabled by default]
/usr/lib/openmpi/include/mpi.h:1197:20: note: expected ‘void *’ but argument is of type ‘int’
worker.c:34:2: warning: passing argument 5 of ‘MPI_Scatter’ makes integer from pointer without a cast [enabled by default]
/usr/lib/openmpi/include/mpi.h:1197:20: note: expected ‘int’ but argument is of type ‘MPI_Comm’
worker.c:34:2: error: too few arguments to function ‘MPI_Scatter’
/usr/lib/openmpi/include/mpi.h:1197:20: note: declared here
worker.c:36:2: warning: passing argument 4 of ‘MPI_Gather’ makes pointer from integer without a cast [enabled by default]
/usr/lib/openmpi/include/mpi.h:1058:20: note: expected ‘void *’ but argument is of type ‘int’
worker.c:36:2: warning: passing argument 5 of ‘MPI_Gather’ makes integer from pointer without a cast [enabled by default]
/usr/lib/openmpi/include/mpi.h:1058:20: note: expected ‘int’ but argument is of type ‘MPI_Comm’
worker.c:36:2: error: too few arguments to function ‘MPI_Gather’
/usr/lib/openmpi/include/mpi.h:1058:20: note: declared here
worker.c:37:2: warning: passing argument 4 of ‘MPI_Scatter’ makes pointer from integer without a cast [enabled by default]
/usr/lib/openmpi/include/mpi.h:1197:20: note: expected ‘void *’ but argument is of type ‘int’
worker.c:37:2: warning: passing argument 5 of ‘MPI_Scatter’ makes integer from pointer without a cast [enabled by default]
/usr/lib/openmpi/include/mpi.h:1197:20: note: expected ‘int’ but argument is of type ‘MPI_Comm’
worker.c:37:2: error: too few arguments to function ‘MPI_Scatter’
/usr/lib/openmpi/include/mpi.h:1197:20: note: declared here
worker.c:40:1: error: expected declaration or statement at end of input
The issue seems to be the formatting of my MPI calls, but I'm not sure what to fix there.
Any help would be greatly appreciated. Thank you!
I was trying to compile a C socket program in CYGWIN gcc but when I compile the client program it gives me the following error
client.h: In function ‘error’:
client.h:11:5: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
exit(1);
^
client.h: In function ‘main’:
client.h:30:9: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
exit(0);
^
client.h:36:5: warning: passing argument 2 of ‘connect’ from incompatible pointer type [enabled by default]
if(connect(sockfd,&serv_addr,sizeof(serv_addr)) < 0)
^
In file included from client.h:3:0:
/usr/include/sys/socket.h:28:7: note: expected ‘const struct sockaddr *’ but argument is of type ‘struct sockaddr_in *’
int connect (int, const struct sockaddr *, socklen_t);
^
And when I tries to compile the server program it gives me the following error
server.h: In function ‘error’:
server.h:8:5: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
exit(1);
^
server.h: In function ‘main’:
server.h:18:9: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
exit(1);
^
server.h:23:5: warning: incompatible implicit declaration of built-in function ‘bzero’ [enabled by default]
bzero((char *) &serv_addr, sizeof(serv_addr));
^
server.h:32:64: error: ‘client’ undeclared (first use in this function)
newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &client);
^
server.h:32:64: note: each undeclared identifier is reported only once for each function it appears in
So what is the solution to this
The error in your client code is because you pass a pointer to a struct sockaddr_in to a parameter that expects it to be a pointer to a struct sockaddr. The error message basically says it all. The error in your server code is because the variable client is not declared anywhere.
The warnings are caused by not including the appropriate include files containing the declarations of exit (include stdlib.h) and bzero (include strings.h). You thus get an implicit declaration and since the compiler knows these functions as standardly built-in functions it mentions that in the warning as well.
Well the issue was that i was trying to compile the linux program in windows.
I'm following the kernel tutorial from here
im having 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 for ‘memcpy’
./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 for ‘memset’
./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 ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘strlen’
main.c:49: warning: return type of ‘main’ is not ‘int’
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 the ones from the tutorial.
I can see that in main.c the functions are defined like so
void *memcpy(void *dest,const void *src, size_t count)
but in my system.h file they are defined like so
extern unsigned char *memcpy(unsigned char *dest,const unsigned char *src, int count)
C is not my primary language but i am in the process of learning it so I apologize if my question is simple but I would think that these definitions should be the same not?
Probably your issue is that size_t isn't the same as int on your platform, or size_t isn't specified correctly at all. The pointer types should be OK (technically, they should match too, but on most systems sizeof(char*) == sizeof(void*)).
If you're developing your own kernel, you'd want to write your own system.h. If you're writing both system.h and main.c, you can make them match up however you'd like. If you look at this page of the tutorial, you'd see that header and C source both declare memcpy as:
unsigned char *memcpy(unsigned char *dest, const unsigned char *src, int count);
But if you download the example source files at the end of the tutorial, you find it is instead:
void *memcpy(void *dest, const void *src, size_t count);
Looking at the top of that file, you find the following comment:
/* bkerndev - Bran's 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. */
It doesn't look like you're trying to follow a tutorial, but rather that you're trying to cut and paste code from a tutorial. That's like trying to learn to perform brain surgery by following along in a book. You might get it to work, but if you don't really understand what you're doing... well, please do the world a favor and don't use it for anything critical.
Replace size_t by int in each method definition on main.c