|
Scores in game |
Specter Phoenix
Member #1,425
July 2001
|
I've been trying to implement a score in game and did: int score; score++; al_draw_textf(font, al_map_rgb(255, 255, 255), 12, 12, ALLEGRO_ALIGN_LEFT, "%d", score); The compiler is telling me I can't convert from const char* to int. Was basically following what I found on the forums http://www.allegro.cc/forums/thread/610620
|
Arthur Kalliokoski
Second in Command
February 2005
|
I copied and pasted your code and neither gcc or g++ complained. What compiler are you using? They all watch too much MSNBC... they get ideas. |
Specter Phoenix
Member #1,425
July 2001
|
Gnu 4.6.3 under Ubuntu.
|
Arthur Kalliokoski
Second in Command
February 2005
|
I'm using 4.5.2 in slackware, doesn't it say which parameter is at fault in the error? [EDIT] I get this if I remove the flags parameter pong.c:111:1: warning: passing argument 5 of 'al_draw_textf' makes integer from pointer without a cast /usr/local/include/allegro5/allegro_font.h:89:1: note: expected 'int' but argument is of type 'char *' pong.c:111:1: warning: passing argument 6 of 'al_draw_textf' makes pointer from integer without a cast /usr/local/include/allegro5/allegro_font.h:89:1: note: expected 'const char *' but argument is of type 'int'
They all watch too much MSNBC... they get ideas. |
Specter Phoenix
Member #1,425
July 2001
|
Nevermind, figured it out, forgot the y value but my mind was completing the code when I read it. For x I had SCREEN_W - 50 and for some reason my mind was doing SCREEN_W for x and 50 for y when I read it. facepalm
|
Audric
Member #907
January 2001
|
These are warnings, I'm surprised you don't get an error about al_draw_textf() not having the right number of arguments. At least at the link step. |
SiegeLord
Member #7,827
October 2006
|
Audric said: I'm surprised you don't get an error about al_draw_textf() not having the right number of arguments. It had the "right" (valid is a better word) number of arguments. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
Specter Phoenix
Member #1,425
July 2001
|
I got errors, but it was errors going on about conversion for the arguments. Unless I misread them it was saying argument 5 was int to const char* and argument 6 was const char* to int but nothing was said about the fact that I was passing one less argument than needed for what I was trying to use it for.
|
Audric
Member #907
January 2001
|
Oh my mistake, it's one of these functions with variable arguments : ... in prototype, so it cannot detect the missing argument. |
Specter Phoenix
Member #1,425
July 2001
|
Audric said: Oh my mistake, it's one of these functions with variable arguments : ... in prototype, so it cannot detect the missing argument. You mean function overloading?
|
Arthur Kalliokoski
Second in Command
February 2005
|
Specter Phoenix said: You mean function overloading? He means the parameters to the format, such as "%d %d %d",var_x,var_y,var_z. They all watch too much MSNBC... they get ideas. |
Audric
Member #907
January 2001
|
I just remembered GCC provides a way to make it check format arguments, it's the __attribute__ ((format)). ... #elif defined ALLEGRO_MINGW32 #define ALLEGRO_FONT_PRINTFUNC(type, name, args, a, b) ALLEGRO_FONT_FUNC(type, name, args) __attribute__ ((format (printf, a, b))) ... So with mingw you get a warning if you mismatch your format and arguments of al_draw_textf(), but not on Linux... |
Luiji99
Member #12,254
September 2010
|
Perhaps someone should patch it? Programming should be fun. That's why I hate Java. |
Audric
Member #907
January 2001
|
Ah no I misread, they have it already. (alconfig.h : definition of AL_PRINTFUNC when _GNUC_ is defined) |
Arthur Kalliokoski
Second in Command
February 2005
|
I tried it again with -O2 -Wall -Wextra (instead of the previous -g) and it still didn't complain, just warnings about unused argv and argc, and "score" was uninitialized. They all watch too much MSNBC... they get ideas. |
Audric
Member #907
January 2001
|
Strange, -Wformat is implied by -Wall, so you should get it. warning: too many arguments for format warning: too few arguments for format warning: format '%d' expects type 'int', but argument 8 has type 'char *'
This is on GCC 4.4.1 TDM-2 mingw32. Maybe you're using an older version that didn't make all these checks. |
Arthur Kalliokoski
Second in Command
February 2005
|
Audric said: Strange, -Wformat is implied by -Wall, so you should get it. Not the same. pepsi@fractal:~ 05:19 PM $ gcc -O2 -Wall -Wextra -c pong.c pong.c: In function 'main': pong.c:275:14: warning: unused parameter 'argc' pong.c:275:27: warning: unused parameter 'argv' pepsi@fractal:~ 05:19 PM $ gcc -O2 -Wall -c pong.c pepsi@fractal:~ 05:19 PM $ gcc -O2 -Wall -c pong.c
They all watch too much MSNBC... they get ideas. |
Luiji99
Member #12,254
September 2010
|
It's not giving a warning because that's not a problem. As far as the compiler's concerned, due to the missing argument, score is being passed as the format message. As such, it can't detect any formatting issues because the format is, itself, invalid. Programming should be fun. That's why I hate Java. |
Temia Eszteri
Member #14,459
July 2012
|
Specter Phoenix said: Nevermind, figured it out, forgot the y value but my mind was completing the code when I read it. For x I had SCREEN_W - 50 and for some reason my mind was doing SCREEN_W for x and 50 for y when I read it. facepalm And this is why it's always best to copy-paste code directly when troubleshooting. “Nothing is withheld from us what we have conceived to do.” —Russell Kirsch |
Specter Phoenix
Member #1,425
July 2001
|
Temia Eszteri said: And this is why it's always best to copy-paste code directly when troubleshooting. Not really, I remember one time on here I posted my code for something asking about doing menus with Allegro's GUI code and there were like 20 posts where everyone said it was something else and it ultimately turned out to be a similar issue as this, had just forgot to pass a 0 for a flag. Took about the same number of posts as here before anyone even caught it because everyone did what I did and kept putting it in mentally . Speaking of which I need to learn menus (game screens) for the start up screens and such .
|
Thomas Fjellstrom
Member #476
June 2000
|
Specter Phoenix said: Not really, Depends if you're showing the actual code you're using or not. Some people tend to not actually show the code that they are actually using. -- |
Specter Phoenix
Member #1,425
July 2001
|
Thomas Fjellstrom said: Depends if you're showing the actual code you're using or not. Some people tend to not actually show the code that they are actually using. True.
|
|