081006 MacGregor/Nibios Taking Quixadhal's fixup_081004 src and adapting to compile with g++ 3.4.6. First pass: compile dies with these errors and fixes: comm.c: In function `void act_new(const char*, CHAR_DATA*, const void*, const void*, int, int)': comm.c:2443: warning: cast from `const void*' to `CHAR_DATA*' discards qualifiers from pointer target type comm.c:2444: warning: cast from `const void*' to `OBJ_DATA*' discards qualifiers from pointer target type comm.c:2445: warning: cast from `const void*' to `OBJ_DATA*' discards qualifiers from pointer target type comm.c:2512: warning: cast from `const void*' to `char*' discards qualifiers from pointer target type comm.c:2513: warning: cast from `const void*' to `char*' discards qualifiers from pointer target type comm.c:2536: warning: cast from `const void*' to `char*' discards qualifiers from pointer target type comm.c:2542: warning: cast from `const void*' to `char*' discards qualifiers from pointer target type The offending lines: 2443: CHAR_DATA *vch = (CHAR_DATA *) arg2; 2444: OBJ_DATA *obj1 = (OBJ_DATA *) arg1; 2445: OBJ_DATA *obj2 = (OBJ_DATA *) arg2; 2512: case 't': i = (char *) arg1; break; 2513: case 'T': i = (char *) arg2; break; 2536: if ( arg2 == NULL || ((char *) arg2)[0] == '\0' ) 2542: one_argument( (char *) arg2, fname ); The first six were pretty straightforward to fix, changing them respectively to: 2443: const CHAR_DATA *vch = (const CHAR_DATA *) arg2; 2444: const OBJ_DATA *obj1 = (const OBJ_DATA *) arg1; 2445: const OBJ_DATA *obj2 = (const OBJ_DATA *) arg2; 2512: case 't': i = (const char *) arg1; break; 2513: case 'T': i = (const char *) arg2; break; 2536: if ( arg2 == NULL || ((const char *) arg2)[0] == '\0' ) We'll defer fixing line 2542 for now, and just recompile with what we have. We now get: comm.c: In function `void act_new(const char*, CHAR_DATA*, const void*, const void*, int, int)': comm.c:2515: error: invalid conversion from `const CHAR_DATA*' to `CHAR_DATA*' comm.c:2515: error: initializing argument 2 of `bool can_see(CHAR_DATA*, CHAR_DATA*)' comm.c:2524: error: invalid conversion from `const OBJ_DATA*' to `OBJ_DATA*' comm.c:2524: error: initializing argument 2 of `bool can_see_obj(CHAR_DATA*, OBJ_DATA*)' comm.c:2530: error: invalid conversion from `const OBJ_DATA*' to `OBJ_DATA*' comm.c:2530: error: initializing argument 2 of `bool can_see_obj(CHAR_DATA*, OBJ_DATA*)' comm.c:2542: warning: cast from `const void*' to `char*' discards qualifiers from pointer target type The offending lines: 2515: case 'N': i = PERS( vch, to ); break; 2524: i = can_see_obj( to, obj1 ) 2530: i = can_see_obj( to, obj2 ) 2542: one_argument( (char *) arg2, fname ); The PERS macro takes us to the can_see() function in handler.c. We change it from bool can_see( CHAR_DATA *ch, CHAR_DATA *victim ) to bool can_see( const CHAR_DATA *ch, const CHAR_DATA *victim ) This in turn requires changing get_trust(), get_skill() and get_curr_stat() all to take const CHAR_DATA * arguments instead of CHAR_DATA *. Fixing can_see_obj() is a bit more straightforward since we only have to change its own arguments to const CHAR_DATA * and const OBJ_DATA *. So now the only problem left is line 2542 and its call to one_argument(). Changing one_argument() to take a const char * as its first argument, and returning a const char *, is going to open up a huge can of worms. The Right Thing To Do at this point would be to make the function take a const char * for its first argument, and return a const char *. This would mean, among other things, that every do_fun would have to take a const char * for their second argument. However this would definitely break about 95% of the existing ROM snippets, and we'd agreed we didn't want to do that. Furthermore, it already compiles just fine with gcc 4.1.x. So pretty much against my better judgement, I copied one_argument() to a new function get_argument(), with get_argument() taking and returning const char *'s, and changed line 2542 to call the new get_argument() function. Okay, it compiles cleanly now! Let's try compiling as gcc instead of g++. Whoops! act_comm.c blows up big time, referencing incomplete data types. The problem is that g++ has its own bool data type and gcc doesn't. So we add a couple lines in merc.h like so: /* * Accomodate both gcc and g++ */ #if !defined __cplusplus typedef unsigned char bool; #endif g++ is still happy, and so is gcc until it gets to act_wiz.c: act_wiz.c: In function `do_clone': act_wiz.c:2386: warning: declaration of 'new_obj' shadows a global declaration recycle.h:81: warning: shadowed declaration is here Hmm, wonder why this didn't show up earlier? Seems to me it should have. Anyway, change the local variable new_obj to cloned_obj and continue. Uh oh, comm.c blows up again, this time over those declarations of system calls at the top of comm.c. Let's extend the comment around the declarations for accept, bind et al to include the declarations for read, select, etc too. I think it would be safe to just remove them but I'll do it conservatively. Okay, another shadow problem in db.c, the variable 'exit' in the function do_dump(). Let's change it to pExit. Now we're getting, of all things, this error: handler.c: In function `unequip_char': handler.c:1646: warning: suggest explicit braces to avoid ambiguous `else' We add curley braces around the for loop inside the 'if', and also around the for-loop itself. Either set resolves the problem, but good practice requires both. Now, finally, it compikes with both g++ and gcc.