Re: ascii wilderness maps

From: Peter Ajamian (pajamian@cheapsam.com)
Date: 11/17/99


Jason Beeland wrote:
> ok, my thanks to everyone who pointed out that this was a c++ program rather
> than C.  I feel somewhat silly, though not too bad since i have actually not
> had any exposure to c++.  Using g++ resulted in many less errors, though
> unfortunately there were still a few.  Here is what g++ resulted in on
> compilation:
> ( The actual file i've been trying to compile can be found at
> ftp://silverun.dynip.com/pub/mapgen.c )

Damn, this looks like a file that's about half way through a conversion from C
to C++, whoever wrote it didn't even change the file extension to c++ or cpp.
Weather it is a badly coded C program that was written using a compiler that
allows C++ features in C programs (there are a few and they only cause problems
in the long run) or it's a really bad conversion from C to C++, either way it
appears that the best way to deal with it is to finish the conversion and get it
to compile as a C++ program.  For starters change the extension from c to cpp or
c++.  Then we'll work through the errors and see what happens...

> mapgen.c: In function `int main(int, char **)':
> mapgen.c:135: warning: name lookup of `i' changed for new ANSI `for' scoping
> mapgen.c:94: warning:   using obsolete binding at `i'

line 135 is the following...

        for ( i = 0; i < maplines; i++ ) {

This leads me to believe it is a half-way finished conversion, at any rate
whoever was converting it they took out the int i declaration at the start of
the function and are declaring it in the function where it's needed, only they
forgot to declare it here, so change the line to the following...

        for (int  i = 0; i < maplines; i++ ) {

It appears that the compiler skipped similar warnings for lines 147 and 178, it
will often do this for implicit declarations, change those lines in the same
manner as above.

> mapgen.c: In function `int WriteRoom(struct FILE *, int, int, int, int,
> struct FILE *)':
> mapgen.c:296: warning: implicit declaration of function `int ltoa(...)'
> /tmp/ccjshLTZ.o: In function `WriteRoom(_IO_FILE *, int, int, int, int,
> _IO_FILE *)':
> /tmp/ccjshLTZ.o(.text+0xd6b): undefined reference to `ltoa'
> collect2: ld returned 1 exit status

Well, there is no ltoa standard function, it is most likely a non standard
function which is included with the compiler of the person who wrote the
program, to use such a function without making provision for compilers that
don't include it is very bad programming practice indeed (although I can't say I
have seen much of "good" programming practice in this file), it appears that the
prototype and function of ltoa should be something like the following...

void ltoa(char *a, long l, size_t length)
{
  char temp[100];

  sprintf(temp, "%ld", l);
  strncpy(a, temp, length);
}

of course, why bother with creating a whole function when not only don't you
need the function, but in addition, you can trim four lines of existing code
down into one, try replacing lines 294 - 297 with the following...

fprintf(outfile, "%ld", (atol(bitvector) + 65536L));

That'll replace four lines of code with one and you won't even need an ltoa
function!


Regards, Peter

     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST