[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
a couple of C questions about ASM-objc
From: |
Paul E. Johnson |
Subject: |
a couple of C questions about ASM-objc |
Date: |
Mon, 15 May 2000 18:11:05 -0500 |
In case you are not keeping score, I'm trying to get playmates on the
Artificial Stock Market at ArtStkMkt.sourceforge.net.
I don't want to waste Marcus's time with this, but I figured there are
many C programmers in this list and somebody is likely to have opinions.
In the ASM version that is written in plain old objective C, I have
trouble compiling some things and I suspect the problems are platform
related.
1. The compiler absolutely hates this in the file error.m:
FILE *msgfile = stderr;
gcc says:
error.m:115: initializer element is not constant
make: *** [error.o] Error 1
What do you think about that one?
2. when I compile I get the error "getwd is not dangerious and should
not be used". In the file "util.m" it is used like this:
(this is a declaration of a global variable)
static const char *workingdir
(here's the usage)
const char *cwd(void)
{
char pathname[MAXPATHLEN+1], *ptr;
int len;
extern char *getwd(char *);
if (workingdir)
return workingdir;
if (getwd(pathname) == NULL)
cerror("cwd", "Unable to get cwd: %s", pathname);
len = strlen(pathname);
ptr = (char *)getmem(sizeof(char)*(len+2));
strcpy(ptr, pathname);
ptr[len++] = PATHSEPCHAR;
ptr[len] = EOS;
workingdir = ptr;
if (debug&DEBUGFILES)
message("#f: cwd: %s", workingdir);
return workingdir;
}
I understand from poking around that getwd () is a BSD-ism that is
deprecated in GlibC-2, and that the alternative is getcwd ( x, n ),
where n is a char pointer and n is the size of space to be allocated for
the path the char pointer points to. Right?
So I would rewrite like this?
const char *cwd(void)
{
if (workingdir)
return workingdir;
else
getcwd( workingdir, MAXPATHLEN+1);
if (workingdir==NULL)
{
printf("couldn't get wd");
exit(1);
}
return workingdir;
}
But looking at this code, I can't understand why it would use "extern
char *getwd( char *); in the first place. It declares a builtin C
library function? And what does extern mean in an "m" file?
--
Paul E. Johnson email: address@hidden
Dept. of Political Science http://lark.cc.ukans.edu/~pauljohn
University of Kansas Office: (785) 864-9086
Lawrence, Kansas 66045 FAX: (785) 864-5700
==================================
Swarm-Modelling is for discussion of Simulation and Modelling techniques
esp. using Swarm. For list administration needs (esp. [un]subscribing),
please send a message to <address@hidden> with "help" in the
body of the message.
==================================
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- a couple of C questions about ASM-objc,
Paul E. Johnson <=