#172048 - zelbo - Mon Jan 11, 2010 9:43 pm
When i compile my program, i get the following warning:
Code: |
c:/devkitPro/projects/Quest_yarlds0.0.0c/source/gameMain.cpp: In function 'int main()':
c:/devkitPro/projects/Quest_yarlds0.0.0c/source/gameMain.cpp:199: warning: deprecated conversion from string constant to 'char*' |
Is this warning a problem? how would i fix this? do i need to fix this?
I've fiddled with it a lot and so far this is what i've gotten to 'work', but i'm not sure it's the right way to do it.
the relevant parts:(lots of other crap chopped out for your convenience)
Code: |
#include <string.h>
char message;
void printMessage(PrintConsole pConsole, char* message)
{
consoleSelect(&pConsole);
iprintf("\x1b[02;00H\n%s", message);
}
int main(void)
{
// snip - console set up, screen mode initialize, blah blah blah...
printMessage(winMessage, "You see Steve the Kobold.");
while(1)
{
}
return 0;
} |
Last edited by zelbo on Tue Jan 12, 2010 2:59 am; edited 1 time in total
#172051 - kusma - Mon Jan 11, 2010 10:27 pm
A string-literal ("text inside quotes") is "const char *" in C, not "char *". So when you're calling printMessage() with a string-literal parameter, you're casting away the const-ness of it. For this reason, some C compilers used to have implicit conversion from "const char *" to "char *", but this have been deprecated.
Change the prototype of printMessage() to "void printMessage(PrintConsole pConsole, const char* message)" to get rid of it.
#172059 - zelbo - Tue Jan 12, 2010 2:59 am
Awesome. Thank you!
#172062 - Ruben - Tue Jan 12, 2010 11:28 am
Hopefully this time I haven't overlooked something >_>'
Code: |
char message; //1st declaration of a variable name 'message'
//another dec? I would recommend that it be changed, or better yet, name the previous variable "gMessage" for 'global'
void printMessage(PrintConsole pConsole, char* message)
{
consoleSelect(&pConsole);
iprintf("\x1b[02;00H\n%s", message);
} |
EDIT:
And yeah, you need to make the string type "const char*" as all variables that can't/shouldn't be edited are constant.
Also, I'm not sure how libnds works, but wouldn't it be more... 'correct' to pass off a *pointer* to the print console rather than the whole struct?
Last edited by Ruben on Tue Jan 12, 2010 4:31 pm; edited 1 time in total
#172064 - Dwedit - Tue Jan 12, 2010 3:24 pm
You aren't changing the message, so you should declare it "const char *" rather than char*.
If you don't, you won't be able to pass in string literals.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."
#172065 - kusma - Tue Jan 12, 2010 4:36 pm
Dwedit wrote: |
You aren't changing the message, so you should declare it "const char *" rather than char*.
If you don't, you won't be able to pass in string literals. |
If you're referring to Ruben's post, I think he was referring to the superfluous "char message;"...
#172068 - zelbo - Tue Jan 12, 2010 9:25 pm
Quote: |
Also, I'm not sure how libnds works, but wouldn't it be more... 'correct' to pass off a *pointer* to the print console rather than the whole struct? |
Probably, but i'm not very good with pointers yet and this is the only way i could get it to work. I tried a few variations with pointers and addresses and blahblahblah everything i did broke it but good. If someone can show me how to do this right, i would appreciate it.
I think this falls into the area of stuff i would call "bad habits i need to break before it's too late". There are a few other things i'm struggling with, but i'd like to try to figure them out before i ask for help.
#172071 - Ruben - Tue Jan 12, 2010 10:53 pm
Well, to pass it off as a pointer, you simply change the declaration to "void printMessage(PrintConsole *pConsole, const char* message)" and when passing the console, you use "printMessage(&myConsole, "Hello World!")"
#172074 - zelbo - Wed Jan 13, 2010 1:41 am
As for the extra declaration, yeah, i'm not using that one. i put it there while trying to make it work, but i've since gotten rid of it. actually, i'm thinking about putting the whole message system into a class and making a message object to handle all that. object oriented, you know?