I am trying to use GetVersionEx() from the Windows API with the OSVERSIONINFOEX structure, but this keeps throwing a warning about an incompatible pointer type:
OSVERSIONINFOEX osInfo;
osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
GetVersionEx(&osInfo);
printf("%ld\n", osInfo.dwBuildNumber);
full warning:
id.c:31:18: warning: passing argument 1 of 'GetVersionExA' from incompatible pointer type [-Wincompatible-pointer-types]
31 | GetVersionEx(&osInfo);
| ^~~~~~~~
| |
| OSVERSIONINFOEX * {aka OSVERSIONINFOEXA *}
In file included from C:/msys64/mingw64/include/winbase.h:36,
from C:/msys64/mingw64/include/windows.h:70,
from id.c:1:
C:/msys64/mingw64/include/sysinfoapi.h:64:61: note: expected 'LPOSVERSIONINFOA' {aka 'struct _OSVERSIONINFOA *'} but argument is of type 'OSVERSIONINFOEX *' {aka 'OSVERSIONINFOEXA *'}
64 | WINBASEAPI WINBOOL WINAPI GetVersionExA (LPOSVERSIONINFOA lpVersionInformation);
| ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
GetVersionEx() expects an OSVERSIONINFO* pointer, not an OSVERSIONINFOEX* pointer. However, the OSVERSIONINFO* pointer can point at an OSVERSIONINFOEX instance, so you just need to use a typecast, eg:
GetVersionEx((LPOSVERSIONINFO)&osInfo);
I am building a string library to support both ascii and utf8.
I create two typedef for t_ascii and t_utf8. ascii is safe to be read as utf8, but utf8 is not safe to be read as ascii.
Do I have any way to issue a warning when implicitely casting from t_utf8 to t_ascii, but not when implicitely casting t_ascii to t_utf8 ?
Ideally, I would want these warnings (and only these warnings) to be issued:
#include <stdint.h>
typedef char t_ascii;
typedef uint_least8_t t_utf8;
int main()
{
t_ascii const* asciistr = "Hello world"; // Ok
t_utf8 const* utf8str = "你好世界"; // Ok
asciistr = utf8str; // Warning: utf8 to ascii is not safe
utf8str = asciistr; // Ok: ascii to utf8 is safe
t_ascii asciichar = 'A';
t_utf8 utf8char = 'B';
asciichar = utf8char; // Warning: utf8 to ascii is not safe
utf8char = asciichar; // Ok: ascii to utf8 is safe
}
Currently, when building with -Wall (and even with -funsigned-char), I get these warnings:
gcc main.c -Wall -Wextra
main.c: In function ‘main’:
main.c:10:35: warning: pointer targets in initialization of ‘const t_utf8 *’ {aka ‘const unsigned char *’} from ‘char *’ differ in signedness [-Wpointer-sign]
10 | t_utf8 const* utf8str = "你好世界"; // Ok
| ^~~~~~~~~~
main.c:12:18: warning: pointer targets in assignment from ‘const t_utf8 *’ {aka ‘const unsigned char *’} to ‘const t_ascii *’ {aka ‘const char *’} differ in signedness [-Wpointer-sign]
12 | asciistr = utf8str; // Warning: utf8 to ascii is not safe
| ^
main.c:16:17: warning: pointer targets in assignment from ‘const t_ascii *’ {aka ‘const char *’} to ‘const t_utf8 *’ {aka ‘const unsigned char *’} differ in signedness [-Wpointer-sign]
16 | utf8str = asciistr; // Ok: ascii to utf8 is safe
| ^
Compile with -Wall. Always compile with -Wall.
<user>#squall:~/src/p1$ gcc -Wall -c test2.c
test2.c: In function ‘main’:
test2.c:9:31: warning: pointer targets in initialization of ‘const t_utf8 *’ {aka ‘const signed char *’} from ‘char *’ differ in signedness [-Wpointer-sign]
9 | t_utf8 const* utf8str = "你好世界";
| ^~~~~~~~~~~~~~
test2.c:11:13: warning: pointer targets in assignment from ‘const t_ascii *’ {aka ‘const char *’} to ‘const t_utf8 *’ {aka ‘const signed char *’} differ in signedness [-Wpointer-sign]
11 | utf8str = asciistr; // Ok: ascii to utf8 is safe
| ^
test2.c:12:14: warning: pointer targets in assignment from ‘const t_utf8 *’ {aka ‘const signed char *’} to ‘const t_ascii *’ {aka ‘const char *’} differ in signedness [-Wpointer-sign]
12 | asciistr = utf8str; // Should issue warning: utf8 to ascii is not safe
| ^
You want it to be safe to cast from t_ascii from t_utf8, but it's simply not. The signedness differs.
The warning is not about the fact that valid utf8 is sometimes not valid ASCII - the compiler knows nothing about that. The warning is about the sign.
If you want an unsigned char, compile with -funsigned-char. But then neither warning will be issued.
(By the way, if you think that type int_least8_t will be able to hold a multibyte char / complete utf8 codepoint encoding - it will not. All int_least8_t and consequently utf8_t in a single compilation unit will have the exact same size.)
Simply compile it with a standard C compiler. What compiler options are recommended for beginners learning C?
Result:
<source>: In function 'main':
<source>:9:31: error: pointer targets in initialization of 'const t_utf8 *' {aka 'const unsigned char *'} from 'char *' differ in signedness [-Wpointer-sign]
9 | t_utf8 const* utf8str = "你好世界"; // Ok
| ^~~~~~~~~~
<source>:11:14: error: pointer targets in assignment from 'const t_utf8 *' {aka 'const unsigned char *'} to 'const t_ascii *' {aka 'const char *'} differ in signedness [-Wpointer-sign]
11 | asciistr = utf8str; // Warning: utf8 to ascii is not safe
| ^
<source>:12:13: error: pointer targets in assignment from 'const t_ascii *' {aka 'const char *'} to 'const t_utf8 *' {aka 'const unsigned char *'} differ in signedness [-Wpointer-sign]
12 | utf8str = asciistr; // Ok: ascii to utf8 is safe
| ^
but not when implicitely casting t_ascii to t_utf8 ?
No you can't have that in standard C, since it's an invalid pointer conversion. You can silence the compiler with an explicit cast, but you are invoking undefined behavior if you do.
Apart from that, you could use C11 _Generic to find out which type uint_least8_t boils down to:
#include <stdint.h>
#include <stdio.h>
#define what_type(obj) printf("%s is same as %s\n", #obj, \
_Generic ((obj), \
char: "char", \
unsigned char: "unsigned char", \
signed char: "signed char") );
int main (void)
{
typedef char t_ascii;
typedef uint_least8_t t_utf8;
t_ascii ascii;
t_utf8 utf8;
what_type(ascii);
what_type(utf8);
}
Output on gcc x86 Linux:
ascii is same as char
utf8 is same as unsigned char
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).
Parser.h
enum { PLUS, MINUS, DIVIDE, MULTIPLY, NUMBER, END } type;
int token;
/* parsing functions */
void parse_token (void);
Parser.c
void get_token (void)
{
token++;
parse_token(); /* LINE 11 */
}
void parse_token (void) /* LINE 14 */
{
if ( strchr ("1234567890.", token) )
type = NUMBER;
else if ( strchr ("+", token) )
type = PLUS;
else if ( strchr ("-", token) )
type = MINUS;
else if ( strchr ("/", token) )
type = DIVIDE;
else if ( strchr ("*",token) )
type = MULTIPLY;
else if ( token == '\0' )
type = END;
else
show_error(strcat("Couldn't parse token : ", token));
}
The Errors
parser.c:14:6: warning: conflicting types for ‘parse_token’ [enabled by default]
parser.c:11:2: note: previous implicit declaration of ‘parse_token’ was here
parser.c: In function ‘parse_token’:
parser.c:16:2: warning: passing argument 2 of ‘strchr’ makes integer from pointer without a cast [enabled by default]
/usr/include/string.h:235:14: note: expected ‘int’ but argument is of type ‘char *’
parser.c:17:3: error: ‘type’ undeclared (first use in this function)
parser.c:17:3: note: each undeclared identifier is reported only once for each function it appears in
parser.c:17:10: error: ‘NUMBER’ undeclared (first use in this function)
parser.c:19:2: warning: passing argument 2 of ‘strchr’ makes integer from pointer without a cast [enabled by default]
/usr/include/string.h:235:14: note: expected ‘int’ but argument is of type ‘char *’
parser.c:20:10: error: ‘PLUS’ undeclared (first use in this function)
parser.c:22:2: warning: passing argument 2 of ‘strchr’ makes integer from pointer without a cast [enabled by default]
/usr/include/string.h:235:14: note: expected ‘int’ but argument is of type ‘char *’
parser.c:23:10: error: ‘MINUS’ undeclared (first use in this function)
parser.c:25:2: warning: passing argument 2 of ‘strchr’ makes integer from pointer without a cast [enabled by default]
/usr/include/string.h:235:14: note: expected ‘int’ but argument is of type ‘char *’
parser.c:26:10: error: ‘DIVIDE’ undeclared (first use in this function)
parser.c:28:2: warning: passing argument 2 of ‘strchr’ makes integer from pointer without a cast [enabled by default]
/usr/include/string.h:235:14: note: expected ‘int’ but argument is of type ‘char *’
parser.c:29:10: error: ‘MULTIPLY’ undeclared (first use in this function)
parser.c:32:10: error: ‘END’ undeclared (first use in this function)
parser.c: In function ‘show_error’:
parser.c:40:2: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
I'm utterly bamboozled. :(.
Any help?
One you get it to compile (by including the header, as Luchian Grigore said), you'll find that you can't do strcat() on a constant string.
The constant string is allocated in read-only memory, and can't be modified. And even if you could modify it, you would be overwriting other things in memory.
You're not including your header, so there's no way for the translation unit to know about the declarations of type and token.
You need:
#include "Parser.h"
at the beginning of the implementation file.