Date: Sat, 13 Apr 1996 03:26:26 -0800 (GMT) From: "Rafael R. Sevilla" To: DJGPP newsgroup mail Subject: DJGPP's strrchr Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII I've been writing a few programs that get their program name with the path stripped off them using strrchr to find the last occurrence of '/' or whatever path separator is used, in argv[0] which is the program name and path. The code looks a bit like: #include char *progname; main(int argc, char *argv[]) { if ((progname = strrchr(argv[0], '/')) == NULL) progname = argv[0]; else progname++; ... } In Unix (GCC 2.7.2 also), Turbo C 2.0, and Watcom C 9.0 this expression compiles fine, with all warnings turned on (changing the '/' to '\\' for Turbo and Watcom of course). But under djgpp this expression causes a cryptic warning: "assignment converts integer to pointer without cast" on the line containing the 'if'. If I understand this correctly, the compiler thinks that strrchr should return an integer, rather than a character pointer, since this is the only assignment I've got on that line. But why? The C standard says it should return a pointer to the last character found. The declaration for strrchr in string.h file looks right. Is this a bug in the port or something? The SunOS 5.3 GCC I use which is precisely the same version as the djgpp port has no problems with these statements. What's going on? Should I just ignore the warning? From experience warnings like that usually lead to GP faults and other unpleasant occurrences, especially when dealing with pointers. Another, unrelated question: when passing full pathnames to djgpp programs what path separator should be used? The traditional DOS backslash or the Unix-style forward slash? The djgpp programs seem to deal with full pathnames in a rather confused and inconsistent manner. ------------------------------------------------------------------------- University of the Philippines Rafael R. Sevilla PABX/OVCA: Diliman Networking Project rsevilla AT sauron DOT upd DOT edu DOT ph -------------------------------------------------------------------------