Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ SMAUG
➜ SMAUG coding
➜ Warning I've never seen before
|
Warning I've never seen before
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Greven
Canada (835 posts) Bio
|
| Date
| Wed 15 Oct 2003 05:36 PM (UTC) |
| Message
| In a project I'm working on, I seem to have come across an warning I don't think I've seen before:warning: passing arg 1 of `smash_space' discards qualifiers from pointer target type
The culprit is this line: fprintf( fp, "%s.race\n", smash_space(race_table[count].race_name) );
My smash_space function is this:char *smash_space( char *str )
{
static char ret[MAX_STRING_LENGTH];
char *retptr;
retptr = ret;
for ( ; *str != '\0'; str++ )
{
if (*str == ' ' )
continue;
else
{
*retptr = *str;
retptr++;
}
}
*retptr = '\0';
return ret;
}
Clearly, my compiler is complaining about the type of information being passed into the function. Any ideas on how I can resolve this warning? It works properly, but I hate having warnings in my code. |
Nobody ever expects the spanish inquisition!
darkwarriors.net:4848
http://darkwarriors.net | | Top |
|
| Posted by
| David Haley
USA (3,881 posts) Bio
|
| Date
| Reply #1 on Wed 15 Oct 2003 05:49 PM (UTC) |
| Message
| | What's the type for race_name in the race_table struct? |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | | Top |
|
| Posted by
| Greven
Canada (835 posts) Bio
|
| Date
| Reply #2 on Wed 15 Oct 2003 08:45 PM (UTC) Amended on Wed 15 Oct 2003 08:46 PM (UTC) by Greven
|
| Message
| |
Nobody ever expects the spanish inquisition!
darkwarriors.net:4848
http://darkwarriors.net | | Top |
|
| Posted by
| Greven
Canada (835 posts) Bio
|
| Date
| Reply #3 on Wed 15 Oct 2003 09:04 PM (UTC) |
| Message
| | Well, apparently the problem is that my race_table is a const structure. Still, I dunno what I would do to fix it. Any ideas? |
Nobody ever expects the spanish inquisition!
darkwarriors.net:4848
http://darkwarriors.net | | Top |
|
| Posted by
| David Haley
USA (3,881 posts) Bio
|
| Date
| Reply #4 on Wed 15 Oct 2003 09:50 PM (UTC) |
| Message
| Change:
char *smash_space( char *str )
to:
char *smash_space( const char *str )
This is generally good practice anyways. If your function isn't going to modify the pointer passed as an argument, the pointer should be passed as const. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | | Top |
|
| Posted by
| Greven
Canada (835 posts) Bio
|
| Date
| Reply #5 on Wed 15 Oct 2003 11:10 PM (UTC) |
| Message
| | cleared it right up, thanks. |
Nobody ever expects the spanish inquisition!
darkwarriors.net:4848
http://darkwarriors.net | | Top |
|
| Posted by
| halkeye
Canada (28 posts) Bio
|
| Date
| Reply #6 on Fri 17 Oct 2003 02:13 AM (UTC) |
| Message
| | Thats what i said! SEEESH |
Gavin
Dark Warriors - Coder
http://darkwars.wolfpaw.net
telnet://darkwars.wolfpaw.net:4848 | | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
21,885 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top