05 Oct, 2008, The_Fury wrote in the 1st comment:
Votes: 0
OK, i have pretty much a full day free to waste however i want to, now i was thinking of doing the const fix. I do not really know where to start, does anyone have any good pointers on where to start and how to approach this mamoth task.
06 Oct, 2008, Conner wrote in the 2nd comment:
Votes: 0
While a search of SmaugMuds.org might be worthwhile, personally I'd start here in seeking said pointers. :wink:
06 Oct, 2008, The_Fury wrote in the 3rd comment:
Votes: 0
Yeah, i knew about those threads, they pretty much cover the why's but not so much a practical how to approach the actual task, pretty much what i was planning to do was change all char * argument to consts and then start fixing the errors i get.
06 Oct, 2008, Guest wrote in the 4th comment:
Votes: 0
typedef void DO_FUN( CHAR_DATA * ch, const char *argument );


That right there will probably get you 90% of your way to finding it all in Smaug. The fallout from that one simple line in mud.h is mind boggling. If you don't have gcc 4.2+ handy, force the warnings with -Wwrite-strings and have fun :)
06 Oct, 2008, The_Fury wrote in the 5th comment:
Votes: 0
Samson said:
and have fun :)


Why do i get this feeling that your sitting at your desk with an evil grin on your face thinking SUCKER LOL. And thanks that was exactly the tip i was after on where to approach this from.
06 Oct, 2008, Guest wrote in the 6th comment:
Votes: 0
Who? Me? Sit around with an evil grin on my face? :devil:

I'm sure David can tell you all the fun stuff you're about to run into since he's the one who did the work in getting the const fix done for SmaugFUSS.
06 Oct, 2008, The_Fury wrote in the 7th comment:
Votes: 0
passing of argument 4 discards qualifiers from target type:

from do_force act_wiz.c

act( AT_IMMORT, "$n forces you to '$t'.", ch, argument, victim, TO_VICT );


Argument 4 of act is void *arg1


What do i do in this situation to fix it, these are the only 2 warnings i have left, the rest are errors of assignment of read only locations.

Errr spoke to soon, i have 100's of warnings still, make clean brought them out. LOL
06 Oct, 2008, Guest wrote in the 8th comment:
Votes: 0
void act( short AType, const char *format, CHAR_DATA * ch, const void *arg1, const void *arg2, int type );


Now you know the kind of stuff this is going to lead you to. You'll need to change the prototype for act() which means of course you need to change the function too, which… you get the idea :)
06 Oct, 2008, The_Fury wrote in the 9th comment:
Votes: 0
I see what you mean, all the other things so far have been easy, Act on the other hand is nasty, i am not sure how to go about this just yet, i think i will look at what David did in fuss1.9 for act.
06 Oct, 2008, The_Fury wrote in the 10th comment:
Votes: 0
cast discards qualifiers from pointer target type.

From act_string comm.c
CHAR_DATA *vch = ( CHAR_DATA * ) arg2;
OBJ_DATA *obj1 = ( OBJ_DATA * ) arg1;
OBJ_DATA *obj2 = ( OBJ_DATA * ) arg2;


Ok these ones have me stumped. I am guessing that i need to cont something in the char_data structure in mud.h for the *vch and obj_data for the other 2?
06 Oct, 2008, David Haley wrote in the 11th comment:
Votes: 0
It's actually pretty easy in all cases but a handful, you just have to understand what the constness means. You need to change a whole bunch of prototypes, but there is rather little code that needs to be changed outside of that.

EDIT: it doesn't like you casting a const thing into a non-const thing of a different type. Just cast it to a const thing, and then make the destination variable const. And be prepared to change a lot of stuff that follows. And if you really need it to be non-const, you might have made the wrong thing const…
06 Oct, 2008, The_Fury wrote in the 12th comment:
Votes: 0
Umm sorry you have lost me totally David,

char *act_string ( const char *format, CHAR_DATA * to, CHAR_DATA * ch, const void *arg1, const void *arg2, int flags )


CHAR_DATA *vch = ( CHAR_DATA * ) arg2;
OBJ_DATA *obj1 = ( OBJ_DATA * ) arg1;
OBJ_DATA *obj2 = ( OBJ_DATA * ) arg2;


I think what you were saying is that arg2 is a const void * and im putting it into CHAR_DATA * and it does not like it because they are different types? Or that i can const something else elsewhere that should not be cosnt?
06 Oct, 2008, Guest wrote in the 13th comment:
Votes: 0
Well I don't know why this would have worked then:
void act( short AType, const string & format, char_data * ch, const void *arg1, const void *arg2, int type )
{
#define ACTF_NONE 0
#define ACTF_TXT BV00
#define ACTF_CH BV01
#define ACTF_OBJ BV02

string txt;
char_data *to;
char_data *third = ( char_data * ) arg1;
char_data *vch = ( char_data * ) arg2;
obj_data *obj1 = ( obj_data * ) arg1;
obj_data *obj2 = ( obj_data * ) arg2;
int flags1 = ACTF_NONE, flags2 = ACTF_NONE;


But the compiler is not complaining about my having done it that way in AFKMud 2.1.

That same segment in SmaugFUSS looks like this now:
void act( short AType, const char *format, CHAR_DATA * ch, const void *arg1, const void *arg2, int type )
{
const char *txt;
const char *str;
CHAR_DATA *to;
CHAR_DATA *vch = ( CHAR_DATA * ) arg2;
#define ACTF_NONE 0
#define ACTF_TXT BV00
#define ACTF_CH BV01
#define ACTF_OBJ BV02

const OBJ_DATA *obj1 = ( const OBJ_DATA * ) arg1;
const OBJ_DATA *obj2 = ( const OBJ_DATA * ) arg2;
int flags1 = ACTF_NONE, flags2 = ACTF_NONE;
06 Oct, 2008, The_Fury wrote in the 14th comment:
Votes: 0
const OBJ_DATA *obj1 = ( const OBJ_DATA * ) arg1;


Doing that in act breaks things like CAN_SEE and all this other stuff that should really have nothing to do with anything.
06 Oct, 2008, The_Fury wrote in the 15th comment:
Votes: 0
Ok, i have manged t get it thus far and am stuck with the following:

imc.c: In function 'imc_parse_packet':
imc.c:2968: warning: passing argument 2 of 'pfun' discards qualifiers from pointer target type
Quote
( *pfun ) ( p, packet );


comm.c: In function 'nanny':
comm.c:1749: warning: assignment discards qualifiers from pointer target type
comm.c:1806: warning: assignment discards qualifiers from pointer target type
Quote
case CON_GET_NEW_CLASS:
argument = one_argument ( argument, arg ); <—-

if ( !str_cmp ( arg, "help" ) )


case CON_GET_NEW_RACE:
argument = one_argument ( argument, arg ); <—-

if ( !str_cmp ( arg, "help" ) )



comm.c: In function 'act_string':
comm.c:2372: warning: cast discards qualifiers from pointer target type
comm.c:2373: warning: cast discards qualifiers from pointer target type
comm.c:2374: warning: cast discards qualifiers from pointer target type
comm.c:2406: warning: cast discards qualifiers from pointer target type
comm.c:2410: warning: cast discards qualifiers from pointer target type
comm.c:2509: warning: cast discards qualifiers from pointer target type
comm.c:2513: warning: cast discards qualifiers from pointer target type
Quote
const char *act_string ( const char *format, CHAR_DATA * to, CHAR_DATA * ch, const void *arg1, const void *arg2, int flags )
{
CHAR_DATA *vch = ( CHAR_DATA * ) arg2; <—
OBJ_DATA *obj1 = ( OBJ_DATA * ) arg1; <—
OBJ_DATA *obj2 = ( OBJ_DATA * ) arg2; <—


comm.c: In function 'act':
comm.c:2540: warning: cast discards qualifiers from pointer target type
comm.c:2592: warning: cast discards qualifiers from pointer target type
comm.c:2592: warning: cast discards qualifiers from pointer target type
comm.c:2596: warning: cast discards qualifiers from pointer target type
comm.c:2596: warning: cast discards qualifiers from pointer target type
comm.c:2671: warning: cast discards qualifiers from pointer target type
comm.c:2671: warning: cast discards qualifiers from pointer target type

Quote
void act ( short AType, const char *format, CHAR_DATA * ch, const void *arg1, const void *arg2, int type )
{
const char *txt;
CHAR_DATA *to;
CHAR_DATA *vch = ( CHAR_DATA * ) arg2; <—

if ( HAS_PROG ( to->in_room, ACT_PROG ) )
rprog_act_trigger ( txt, to->in_room, ch, ( OBJ_DATA * ) arg1, ( void * ) arg2 ); <—

for ( to_obj = to->in_room->first_content; to_obj; to_obj = to_obj->next_content )
if ( HAS_PROG ( to_obj->pIndexData, ACT_PROG ) )
oprog_act_trigger ( txt, to_obj, ch, ( OBJ_DATA * ) arg1, ( void * ) arg2 ); <—

if ( MOBtrigger )
{
/*
* Note: use original string, not string with ANSI. – Alty
*/
mprog_act_trigger ( txt, to, ch, ( OBJ_DATA * ) arg1, ( void * ) arg2 ); <—
}
}


The 3 act triggers are declared thus


The 3 act triggers are declared thus
[quote
void oprog_act_trigger( const char *buf, OBJ_DATA *mobj, CHAR_DATA *ch, OBJ_DATA *obj, const void *vo );
[/quote]

And there are a bunch of others in mprogs as well. Anyone got some thoughts on these ones above?
06 Oct, 2008, quixadhal wrote in the 16th comment:
Votes: 0
Hmmmm, interesting!

When I just recently did a quick cleanup of ROM, I tossed my diffs up and one of the guys using an OLD compiler (gcc 3.4) got some warnings of this type.

I'm beginning to wonder if the gcc team argues over which warnings should be included in -Wall. :)
06 Oct, 2008, The_Fury wrote in the 17th comment:
Votes: 0
I kind of agree with you, some of those warnings are on code that IMO should work, as it the do in other smaug bases that have been fixed for constness. My compiler is not all that old, gcc (GCC) 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)
06 Oct, 2008, MacGregor wrote in the 18th comment:
Votes: 0
Actually, -Wall was never intended to turn on literally all warnings.

From the gcc documentation:
info:/gcc/Warning Options said:
The following `-W…' options are not implied by `-Wall'. Some of them warn about constructions that users generally do not consider questionable, but which occasionally you might wish to check for; others warn about constructions that are necessary or hard to avoid in some cases, and there is no simple way to modify the code to suppress the warning.
06 Oct, 2008, David Haley wrote in the 19th comment:
Votes: 0
The_Fury said:
Doing that in act breaks things like CAN_SEE and all this other stuff that should really have nothing to do with anything.

Actually, that has everything to do with everything… Functions like that are almost poster-boy examples of functions that should take all const arguments.

Of course, making changes like this will cause ripple effects through the entire code, but, well, that's the way it is. We're paying now for improper use of const by our "forefathers". :wink: I suggest you look at the latest SmaugFUSS to see an example of code that now compiles cleanly at least of 4.2 (I haven't tried on 4.3 yet).
07 Oct, 2008, Guest wrote in the 20th comment:
Votes: 0
SmaugFUSS 1.9 compiles clean on 4.3 now as well after last night when the bug in the weather code was fixed. It was already just about there anyway except for the weather bug and one ambiguous else warning that wasn't coming up before.
0.0/20