Paul Gilmartin wrote:
> Are questions about C better asked here or on MVS-OE? Surely
> not on ASSEMBLER_LIST -- it's far too busy this week with a
> nostalgia thread.
>
> The C test program:
> /* ---------------------------------------------------------*/
> #include <stdarg.h>
> #include <stdio.h>
> #include <string.h>
>
> static char buffer[ 100 ];
>
> static void f2( char *fmt, va_list xp ) {
> va_list ap;
> char *a;
>
> memcpy( &ap, &xp, sizeof( va_list ) );
> printf("Format: \"%s\"\n", fmt );
> a = va_arg( ap, char * ); printf("First : \"%s\"\n", a );
> a = va_arg( ap, char * ); printf("Second: \"%s\"\n", a );
>
> memcpy( &ap, &xp, sizeof( va_list ) );
> printf( "\nRetrying\n" );
> a = va_arg( ap, char * ); printf("First : \"%s\"\n", a );
> a = va_arg( ap, char * ); printf("Second: \"%s\"\n", a );
>
> memcpy( &ap, &xp, sizeof( va_list ) );
> printf( "\nTrying vsnprintf();\n" );
> vsnprintf( buffer, 99, fmt, ap );
> printf( "%s\n", buffer );
> return; }
>
> static void f1( char *fmt, ... ) {
> va_list ap;
> char *a;
>
> va_start( ap, fmt );
> f2( fmt, ap );
> return; }
>
> int main( void ) {
>
> f1( " %s -- %s ", "foo", "bar" );
>
> return( 0 ); }
> /* ---------------------------------------------------------*/
>
> On Solaris and OS X prints, as I expect:
>
> Format: " %s -- %s "
> First : "foo"
> Second: "bar"
>
> Retrying
> First : "foo"
> Second: "bar"
>
> Trying vsnprintf();
> foo -- bar
>
> But on z/OS 1.10 and 1.7, the unexpected:
>
> Format: " %s -- %s "
> First : " %s -- %s "
> Second: "foo"
>
> Retrying
> First : " %s -- %s "
> Second: "foo"
>
> Trying vsnprintf();
> %s -- %s -- foo
>
> Do I fail to understand something, or have I (again)
> encountered a bug? I'll welcome any workaround that
> doesn't break compatibility with the other 2 systems.
> I'll likewise welcome a test on another system (Linux?)
>
> Thanks,
> gil
"memcpy( &ap, &xp, sizeof( va_list ) );" is not legal C. Either use the
c99 va_copy ("va_copy(ap,xp)") created for this purpose or define
_VARARG_EXT before including stdarg.h. Up until c99 there was no defined
way to do what you were trying to do although your method as well as
direct assignment worked on many but not all systems.
h
>
>
> ----------------------------------------------------------------------
> For IBM-MAIN subscribe / signoff / archive access instructions,
> send email to [email protected] with the message: GET IBM-MAIN INFO
> Search the archives at http://bama.ua.edu/archives/ibm-main.html
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: GET IBM-MAIN INFO
Search the archives at http://bama.ua.edu/archives/ibm-main.html