On Tue, 16 Nov 1999, 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 ) > > mapgen.c:135: warning: name lookup of `i' changed for new ANSI `for' scoping > mapgen.c:94: warning: using obsolete binding at `i' Code like the following is ILLEGAL according to C++ standards: for (int i = 0; i < 10; i++) { ... } table[i] = ...; If 'i' really needs to live beyond the 'for' block, it should be changed to read: int i; for (i = 0; i < 10; i++) { ... } table[i] = ...; This is because there was some initial confusion (or, perhaps, disagreement) about what exactly the scope of a variable declared in a 'for' statement should be. Many implementations had the declared variable exist after the 'for' block. The ANSI standard clarified matters, and instituted some new scoping rules specifically for the 'for' statement. Specifically, a variable declared within the 'for' statement inherets the scope of the 'for' block. In other words, the variable does not exist after the 'for' block. > mapgen.c: In function `int WriteRoom(struct FILE *, int, int, int, int, > struct FILE *)': > mapgen.c:296: warning: implicit declaration of function `int ltoa(...)' This function isn't part of the C++ libraries. From its function name I infer that it means to take a long integer and produce a string from it. It should be fairly easy to write a good version of this, but I'm in a bit of a hurry, and since the code isn't too crucial, you can get away with the ugly hack: char *ltoa (long l) { static char retval[16]; sprintf(retval, "%li", l); return (retval); } Please note that the return value is static, which means if you want to keep it unchanged through multiple calls, you should copy the return value using strcpy() or strdup() or something similar, i.e., char *ptr = ltoa(4); char *ptr2 = ltoa(5); char *ptr3 = ltoa(6); printf("%s%s%s\n", ptr, ptr2, ptr3); might lead you to believe your computer is possessed. -dak +------------------------------------------------------------+ | 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