07 Nov, 2011, arholly wrote in the 1st comment:
Votes: 0
Hello:
I am trying to cleanup the code (and continue to enhance my own knowledge). So, I was using something Darien suggested for finding problems in the code by enforcing the ansi rules. Soo….I did it and got an error I do not understand.
This is what I got:
act_comm.c: In function do_delete:
act_comm.c:47: error: PLAYER_DIR undeclared (first use in this function)
act_comm.c:47: error: (Each undeclared identifier is reported only once
act_comm.c:47: error: for each function it appears in.)
make: *** [act_comm.o] Error 1

What does it mean that it is undeclared? I can find it in our .h file where it declares the path for PLAYER_DIR.
Here is the do_delete
void do_delete( CHAR_DATA *ch, char *argument)
{
char strsave[MAX_INPUT_LENGTH];

if (IS_NPC(ch))
return;

if(ch->desc->editor)
{
send_to_char("You can't delete yourself while in an editor.\n\r", ch);
return;
}

if (ch->pcdata->confirm_delete)
{
if (argument[0] != '\0')
{
send_to_char("Delete status removed.\n\r",ch);
ch->pcdata->confirm_delete = FALSE;
return;
}
else
{
sprintf( strsave, "%s%s", PLAYER_DIR, capitalize( ch->name ) );
wiznet("$N turns $Mself into line noise.",ch,NULL,0,0,0);
stop_fighting(ch,TRUE);
clear_orgs(ch);
do_function(ch, &do_quit, "");
unlink(strsave);
return;
}
}

if (argument[0] != '\0')
{
send_to_char("Just type delete. No argument.\n\r",ch);
return;
}

ch->survey = survey_list;
if(ch->survey) survey_to_char(ch);
send_to_char("Type delete again to confirm this command.\n\r",ch);
send_to_char("WARNING: this command is irreversible.\n\r",ch);
send_to_char("Typing delete with an argument will undo delete status.\n\r",
ch);
ch->pcdata->confirm_delete = TRUE;
wiznet("$N is contemplating deletion.",ch,NULL,0,0,get_trust(ch));
}

#if defined(macintosh)
#define PLAYER_DIR "" /* Player files */
#endif

#if defined(MSDOS)
#define PLAYER_DIR "../player/" /* Player files */
#endif

#if defined(unix)
#define PLAYER_DIR "../player/" /* Player files */
#endif


Is it the macintosh part has nothing in it?

Thanks in advance.
Arholly
07 Nov, 2011, Runter wrote in the 2nd comment:
Votes: 0
Dunno, what are you running it on?
07 Nov, 2011, arholly wrote in the 3rd comment:
Votes: 0
Linux.
07 Nov, 2011, arholly wrote in the 4th comment:
Votes: 0
Is it because it is buried in an if statement? If so, how do I fix this?
07 Nov, 2011, Rarva.Riendf wrote in the 5th comment:
Votes: 0
try to add a #if defined(linux) case
07 Nov, 2011, David Haley wrote in the 6th comment:
Votes: 0
If you're running Linux, 'unix' should already be defined.

$ cat test.c

#include <stdio.h>

int main() {
#ifdef unix
printf("unix");
#else
printf("no unix");
#endif
return 0;
}


$ uname -a
Linux www.the-haleys.com 2.6.39.1-linode34 #1 SMP Tue Jun 21 10:29:24 EDT 2011 i686 GNU/Linux
$ gcc test.c
$ ./a.out
unix
$



Perhaps the relevant .h file that defines PLAYER_DIR hasn't been included or something.
08 Nov, 2011, arholly wrote in the 7th comment:
Votes: 0
OK, I'm definitely linux and I did David's little test and it says I'm unix (I'm linux actually, but whose counting). And no, the .h file is included.
#if defined(macintosh)
#include <types.h>
#else
#include <sys/types.h>
#include <sys/time.h>
#endif

#include <stdlib.h>
#include <time.h>

#include "twilight.h"
#include "recycle.h"
#include "tables.h"
#include "lookup.h"
#include "interp.h"

twilight.h is where the PLAYER_DIR is defined. Again, it works fine unless I try and force it compile with ANSI standards and it is saving player files there, so I know it is working. Just a curious error message.

Arholly
08 Nov, 2011, David Haley wrote in the 8th comment:
Votes: 0
When you compile it with forced standards, does it issue any warnings? It's quite possible that the code you pasted doesn't meet strict ANSI standards when it comes to how the if-defined statement is constructed.

Try replacing #if defined(unix) with #ifdef unix.
08 Nov, 2011, arholly wrote in the 9th comment:
Votes: 0
Tried that, compiled clean without the -pedantic -ansi. When I added it back into the makefile, it tossed the same error:
act_comm.c: In function do_delete:
act_comm.c:47: error: PLAYER_DIR undeclared (first use in this function)
act_comm.c:47: error: (Each undeclared identifier is reported only once
act_comm.c:47: error: for each function it appears in.)
make: *** [act_comm.o] Error 1


Edit: Sorry, those are the errors it tosses in answer to the other question.
08 Nov, 2011, Runter wrote in the 10th comment:
Votes: 0
Well, it looks like for whatever reason those macros aren't ever coming truthy. Testing for OS isn't a very bulletproof way in preprocessor anyways. It's different for different compilers, and for different versions of operating systems. There's only a few OS that are really targeted by you here (As we see here, just 3) and I find it much more reliable to pass that environment setting to the compiler via configuration. I don't expect you to do that, so I don't really see anything wrong here with just removing the if statements and making a single define for the directory location. 1 As it stands there it will be broken for OSX (most popular platform for mac dev atm), anyways! I think it actually supports more just by removing that mess and just using "../players/" for all cases. Or maybe something like this if you really wanted:

#ifndef defined(windows) || defined(macintosh) || defined(linux)
#error This operating system is not a supported platform.
#elseif defined(macintosh)
#define PLAYER_DIR ""
#else
#define PLAYER_DIR "../players/"
#end


I don't see the point, but this is really what you're kinda doing already. Since if it's not one of these three (or if for some reason that environment var isn't defined) it will be guaranteed to have undefined reference to PLAYER_DIR. But without the nice message.


1.
#include <stdio.h>

int main() {
#ifdef macintosh
printf("mac");
#else
printf("no mac");
#endif
return 0;
}

battlegalaxy said:
battlegalaxy:~ jeffreybasurto$ gcc test.c
battlegalaxy:~ jeffreybasurto$ ./a.out
no mac
battlegalaxy:~ jeffreybasurto$ gcc -ansi -dM -E test.c | grep "macintosh"
battlegalaxy:~ jeffreybasurto$ gcc -ansi -dM -E test.c | grep "APPLE"
#define __APPLE_CC__ 5666
#define __APPLE__ 1


Oh, I should mention I'm using OSX.
08 Nov, 2011, arholly wrote in the 11th comment:
Votes: 0
Changing it to:
#if defined(macintosh)
#define PLAYER_DIR ""
#else
#define PLAYER_DIR "../players/"
#endif

For whatever reason did it. Now it's giving me similar errors and I know how to fix it. Thanks!

Arholly
08 Nov, 2011, Runter wrote in the 12th comment:
Votes: 0
arholly said:
Changing it to:
#if defined(macintosh)
#define PLAYER_DIR ""
#else
#define PLAYER_DIR "../players/"
#endif

For whatever reason did it. Now it's giving me similar errors and I know how to fix it. Thanks!

Arholly


You should do gcc -ansi -dM -E whateverfile and see what environment variables it's setting up. It's probably a good idea to figure out why in one case msdos was defined and the other it was not. Or maybe why the defined() isn't truthy. Dunno. In any event, the code you changed it to is probably more portable than before. If you ever do figure it out please update the thread. I'd personally like to know what was going on.
08 Nov, 2011, arholly wrote in the 13th comment:
Votes: 0
OK, what is this command doing? Showing all the defines, correct?
08 Nov, 2011, Runter wrote in the 14th comment:
Votes: 0
arholly said:
OK, what is this command doing? Showing all the defines, correct?


Yeah, it shows everything defined by the environment. So msdos would be there, i guess. Although I wouldn't expect it to be, honestly. I'd expect something like _WIN32_ or something. So it's interesting it was working at all to me.
09 Nov, 2011, David Haley wrote in the 15th comment:
Votes: 0
It worked because macintosh is likely not defined, and so the else kicks in and you're setting it to the right directory.
09 Nov, 2011, arholly wrote in the 16th comment:
Votes: 0
Quote
#include <stdio.h>

int main() {
#ifdef macintosh
printf("mac");
#else
printf("no mac");
#endif
return 0;
}

Did this and I'm no mac…
09 Nov, 2011, Runter wrote in the 17th comment:
Votes: 0
contrived is contrived

#ifdef computer
printf("running on a computer");
#else
printf("Not running on a computer.");
#endif
09 Nov, 2011, arholly wrote in the 18th comment:
Votes: 0
LOL. Ok, point taken. But, still, any idea why it wouldn't see the NULL_FILE?
09 Nov, 2011, arholly wrote in the 19th comment:
Votes: 0
OK, so I have to make an assumption here. I put the #defines back to the way they were to start and realized something, it's not finding any of the #defines.
#if defined(macintosh)
#define PLAYER_DIR "../player/" /* Player files */
#define PLAYER_BACKUP_DIR "../player/backup/" /* Player backup files */
#define CONCEPT_DIR "../data/concepts/" /* Concept files*/
#define NPC_DIR "../npc/" /* NPC files */
#define AREA_DIR "../area/" /* Area files */
#define ORG_DIR "../orgs/" /* Org files */
#define SURVEY_DIR "../data/survey/" /* Survey files */
#define LOG_DIR "../log/" /* Log files */
#define TEMP_FILE "mudtmp"
#define NULL_FILE "proto.are" /* To reserve one stream */
#endif

#if defined(MSDOS)
#define PLAYER_DIR "../player/" /* Player files */
#define PLAYER_BACKUP_DIR "../player/backup/" /* Player backup files */
#define CONCEPT_DIR "../data/concepts/" /* Concept files*/
#define NPC_DIR "../npc/" /* NPC files */
#define AREA_DIR "../area/" /* Area files */
#define ORG_DIR "../orgs/" /* Org files */
#define SURVEY_DIR "../data/survey/" /* Survey files */
#define LOG_DIR "../log/" /* Log files */
#define TEMP_FILE "mudtmp"
#define NULL_FILE "nul" /* To reserve one stream */
#endif

#if defined(unix)
#define PLAYER_DIR "../player/" /* Player files */
#define PLAYER_BACKUP_DIR "../player/backup/" /* Player backup files */
#define CONCEPT_DIR "../data/concepts/" /* Concept files*/
#define NPC_DIR "../npc/" /* NPC files */
#define AREA_DIR "../area/" /* Area files */
#define ORG_DIR "../data/orgs/" /* Org files */
#define SURVEY_DIR "../data/survey/" /* Survey files */
#define LOG_DIR "../log/" /* Log files */
#define TEMP_FILE "../player/mudtmp"
#define NULL_FILE "/dev/null" /* To reserve one stream */
#endif

I ran the command that displays all the #defines and none of them which are OS dependent were in there. Why on Earth would that be?
09 Nov, 2011, Runter wrote in the 20th comment:
Votes: 0
The bottom line is that testing for OS in this manor isn't a bulletproof solution since it's related to your compiler and the environment from which you compile. Do you even know what your environment and operating system are? For example, __APPLE__ with gcc is recommended to test against for OSX (which is a mac operating system). Nothing your testing against up there would work with OSX and gcc I believe. So this type of testing for operating system is questionable for more than a hobby horse project. Which I acknowledge this probably is, but ultimately if learning is your goal it might be okay to consider better solutions. I would much prefer a configuration that you pass to gcc in your make file based on the operating system. Because *that is bulletproof*. You should always know the operating system you're deploying on. If you don't, you're got bigger problems here than why your code isn't compiling.

For example: gcc -D lol_windows file.c

So you could add -D your_platform to the make file for the gcc line…

and ultimately if so inclined: make platform=lol_windows

Although it's somewhat common from yesteryear to see multiple make files for different platforms.

Then your code can do:
#ifdef lol_windows 
printf("Yes, configured to use windows.");
#end


I'm not a C developer so I don't know best practices here, really. I just know that the sniffing for OS that is going on here isn't really going to be effective without many more cases and or's in the code, and probably shouldn't be happening at all since I see not much value in duplicating defines across OS and just failing when the OS isn't defined above. I'm more than happy assuming that the player directory is fine for all practical cases. Then have an exception to the rule for other cases…if they even practically exist for you. I suspect modern linux, windows, and mac will all be able to support the same definitions, honestly. I'd be very surprised if that was useful for anything but legacy. I wouldn't welcome any unnecessary inconsistency across platform builds. Also, are you writing this to distribute it? If not, you can be fairly certain about what your platform is. And even if you want to support other platforms you can be fairly certain it's not going to be something archaic.

Because really, if you want to spend time supporting operating systems your code won't ever be compiled under… I've got a very long list for you to get on top of supporting.
0.0/28