Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!pyrltd!tetrauk!rick From: rick@tetrauk.UUCP (Rick Jones) Newsgroups: comp.lang.eiffel Subject: Re: formated string objects Keywords: sprintf like routine Message-ID: <1071@tetrauk.UUCP> Date: 7 Jan 91 12:23:25 GMT References: <457@kepler1.kepler.com> Reply-To: rick@tetrauk.UUCP (Rick Jones) Organization: Tetra Ltd., Maidenhead, UK Lines: 47 In article <457@kepler1.kepler.com> fcaggian@kepler.com (Frank Caggiano) writes: >The following c routine is something I've wanted to write for >a while now. It makes creating formatted string objects >easier. I hate to devalue your work, but if your system has the vprintf() set of functions, you can do this extremely simply. It would look like: #include #include <_eiffel.h> #ifndef BUFSIZ #define BUFSIZ 512 #endif BUFSIZ OBJPTR format_obj(fmt, va_alist) char *fmt; va_dcl /* the missing ; IS RIGHT see varargs */ { va_list ap; char buf[BUFSIZ]; va_start (ap); if (vsprintf (buf, fmt, ap) >= BUFSIZ) { /* PANIC - buffer overrun, need some program abort code here */ } va_end (ap); return (MakeStr (buf)); } You might want to make BUFSIZ something really big to make the probability of buffer overrun very low. I'm not sure of the extent to which vsprintf() is supported. It's standard in System V, but may not be in BSD. The neatest solution is to use this routine, and then if you haven't got vsprintf() in your library write it using the code Frank posted in his article. The almost identical code was recently posted in comp.lang.c for just this purpose. -- Rick Jones Tetra Ltd. Maidenhead, Was it something important? Maybe not Berks, UK What was it you wanted? Tell me again I forgot rick@tetrauk.uucp -- Bob Dylan