swh@hpcupt1.HP.COM (Steve Harrold) (10/12/89)
<varargs.h> for Turbo C ? The Turbo C compiler product does NOT supply <varargs.h> in its include libraries. (Perhaps because it is not ANSI enough?) Has anyone developed a suitable <varargs.h> file for use with Turbo C? And, if so, would you e-mail me a copy, or better yet, post it. This would be very helpful when porting C code from a U**X environment. -- --------------------- Steve Harrold swh@hpda.hp.com ...hplabs!hpda!swh HPG200/11 (408) 447-5580 ---------------------
sidney@saturn.ucsc.edu (Sidney Markowitz ) (10/13/89)
In article <5940011@hpcupt1.HP.COM> swh@hpcupt1.HP.COM (Steve Harrold) writes: ><varargs.h> for Turbo C ? > >The Turbo C compiler product does NOT supply <varargs.h> in its include My Turbo C 2.0 reference manual says that the va_... stuff is in stdarg.h, so you don't need any varargs.h. A quick glance at stdarg.h showed definitions for va_start, va_arg, va_end, and the type va_list. -- sidney markowitz <sidney@saturn.ucsc.edu>
lwh@harpsichord.cis.ohio-state.edu (Loyde W Hales) (10/13/89)
>The Turbo C compiler product does NOT supply <varargs.h> in its include >libraries. (Perhaps because it is not ANSI enough?) > >Has anyone developed a suitable <varargs.h> file for use with Turbo C? >And, if so, would you e-mail me a copy, or better yet, post it. > >This would be very helpful when porting C code from a U**X environment. It does, Steve, have a variable-arguments header (at least in Ver. 1.5 and later). Your problem is that you are looking in the wrong place. For some reason they put it in <stdarg.h>, not the more common <vararg.h>. (Actually, I know the reason. Remember that ANSI is a draft; for distribution reasons many argued that the stuff should be in <stdarg.h> anyway. This didn't happen, for consistency reasons.) If the name is that important to you, you can redefine it in the OS or via #define. -=- Department of Computer and Information Science Loyde W. Hales, II The Ohio State University lwh@cis.ohio-state.edu 2036 Neil Avenue Mall, Columbus, Ohio 43201
swh@hpcupt1.HP.COM (Steve Harrold) (10/13/89)
Re: <varargs.h> vs <stdarg.h> Even though the <stdarg.h> file has definitions for "va_start", "va_arg", and so on, these definitions are not the same as found in the <varargs.h> file. #include <varargs.h> #include <stdarg.h> void va_start(argptr) ; void va_start(argptr,prevparam) ; type va_arg(argptr,type) ; type va_arg(argptr,type) ; void va_end(argptr) ; void va_end(argptr) ; va_alist va_list argptr; va_dcl type function(va_alist) type function(param) va_dcl /* no semicolon */ type param ; {...code...} {...code...} Even though the files are short, the #defines are rather convoluted, rather reminiscent of APL style coding. Rather than spend the time to study how stacks are created and manipulated by the Turbo C compiler and then to produce a reliable "port" of Turbo C's <stdarg.h> file to <varargs.h> (including the labor of creating test cases), I've always resorted to dropping Turbo C for Microsoft C whenever I handle source code that uses <varargs.h>. I'm still hopeful that some kind soul will step forward with a solution. -- --------------------- Steve Harrold swh@hpda.hp.com ...hplabs!hpda!swh HPG200/11 (408) 447-5580 ---------------------
henry@utzoo.uucp (Henry Spencer) (10/13/89)
In article <5940011@hpcupt1.HP.COM> swh@hpcupt1.HP.COM (Steve Harrold) writes: >The Turbo C compiler product does NOT supply <varargs.h> in its include >libraries. (Perhaps because it is not ANSI enough?) <varargs.h> is not ANSI at all. Try looking for <stdarg.h>. (The differences are small but significant.) -- A bit of tolerance is worth a | Henry Spencer at U of Toronto Zoology megabyte of flaming. | uunet!attcan!utzoo!henry henry@zoo.toronto.edu
gwyn@smoke.BRL.MIL (Doug Gwyn) (10/14/89)
In article <5940011@hpcupt1.HP.COM> swh@hpcupt1.HP.COM (Steve Harrold) writes: ><varargs.h> for Turbo C ? >This would be very helpful when porting C code from a U**X environment. You'd be much better off converting the code to use <stdarg.h>, since the C implementation may not support the old <varargs.h> mechanism. Generally I write my variadic functions to work both ways, depending on #if __STDC__ to control the particulars.
gwyn@smoke.BRL.MIL (Doug Gwyn) (10/14/89)
In article <66595@tut.cis.ohio-state.edu> Loyde W Hales <lwh@cis.ohio-state.edu> writes:
-... Your problem is that you are looking in the wrong place. For some
-reason they put it in <stdarg.h>, not the more common <vararg.h>. (Actually,
-I know the reason. Remember that ANSI is a draft; for distribution reasons
-many argued that the stuff should be in <stdarg.h> anyway. This didn't
-happen, for consistency reasons.)
-If the name is that important to you, you can redefine it in the OS or via
-#define.
What in the world is this that you "know"??
<stdarg.h> is in the final C Standard; it replaces the functionality
of the widely-used <varargs.h> with a somewhat incompatible interface,
and requires that variadic functions be declared with the ,... notation.
gwyn@smoke.BRL.MIL (Doug Gwyn) (10/16/89)
In article <5940012@hpcupt1.HP.COM> swh@hpcupt1.HP.COM (Steve Harrold) writes: >Even though the <stdarg.h> file has definitions for "va_start", "va_arg", >and so on, these definitions are not the same as found in the <varargs.h> >file. That's right. <stdarg.h> facilities were based on traditional <varargs.h>, with some adjustments deemed to be necessary in some potential implementation environments: variadic functions require special ,... declaration syntax so the compiler can give them special linkage if necessary va_alist and va_dcl are replaced by the ,... style function header va_start() is given a fixed argument as a "handle" to allow the implementation to know where the variadic arguments are va_list may be, but is not required to be, an array type >Even though the files are short, the #defines are rather convoluted, >rather reminiscent of APL style coding. That's okay, you shouldn't be looking at them. >Rather than spend the time to study how stacks are created and manipulated >by the Turbo C compiler and then to produce a reliable "port" of Turbo C's ><stdarg.h> file to <varargs.h> (including the labor of creating test >cases), I've always resorted to dropping Turbo C for Microsoft C whenever >I handle source code that uses <varargs.h>. >I'm still hopeful that some kind soul will step forward with a solution. I already suggested a solution, namely, convert the code to use the equivalent <stdarg.h> facilities. Here is a typical example of code that works with either implementation: /* typical declaration, e.g. in a package interface header: */ #ifdef __STDC__ extern void ErPrintf( const char *, ... ); #else extern void ErPrintf(); #endif /* typical definition: */ #ifdef __STDC__ #include <stdarg.h> #else #include <varargs.h> #endif #ifdef __STDC__ void ErPrintf( const char *format, ... ) #else /*VARARGS*/ void ErPrintf( va_alist ) va_dcl #endif { #ifndef __STDC__ register const char *format; #endif va_list ap; #ifdef __STDC__ va_start( ap, format ); #else va_start( ap ); format = va_arg( ap, const char * ); #endif (void)vfprintf( stderr, format, ap ); (void)fflush( stderr ); va_end( ap ); }
gwyn@smoke.BRL.MIL (Doug Gwyn) (10/16/89)
In article <11295@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn) writes: > /* typical definition: */ Oops, you need to insert #include <stdio.h> in here too, since my adapted example invokes stdio functions.
ok@cs.mu.oz.au (Richard O'Keefe) (10/16/89)
In article <11295@smoke.BRL.MIL>, gwyn@smoke.BRL.MIL (Doug Gwyn) writes:
: I already suggested a solution, namely, convert the code to use the
: equivalent <stdarg.h> facilities. Here is a typical example of code
: that works with either implementation:
A public vote of thanks for posting that. I have saved a copy and mean
to follow it religiously. Postings like that make comp.lang.c worthwhile.
sidney@saturn.ucsc.edu (Sidney Markowitz ) (10/16/89)
In article <11295@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn) writes: > [...] Here is a typical example of code >that works with either implementation: > #ifdef __STDC__ I would suggest one modification to this. TurboC only defines __STDC__ if you specify the -A (ANSI compatibility) flag when compiling. I would define my own flag STDVARARGS if __STDC__ or __TURBOC__ is defined and then use that, so you have the option of using conditionalized TurboC extensions if you want to. -- sidney markowitz <sidney@saturn.ucsc.edu or sidney@ai.mit.edu>