Re: [cc65] Compiler: Should xvsnprintf() work?

From: Ullrich von Bassewitz <uz1musoftware.de>
Date: 2013-03-23 23:39:46
On Sat, Mar 23, 2013 at 10:54:08PM +0100, Christian Krüger wrote:
> Am 23.03.2013 21:10, schrieb Ullrich von Bassewitz:
> >-v please.
>
> ??? - do you mean a verbose explanation?

Yes. You stated that you think something is wrong, but without any reasoning.

> If so, at least in my environment (MSVC10), va_list is a typedef to
> char* so the structure 'PrintfCtrl' has an uninitialized pointer if
> 'ap'
> is e.g. used as copy destination in va_copy.

Sorry, but I still don't get it.

    va_copy (P.ap, ap);

is a standard function/macro in C99, which is supposed to copy "ap" into
"P.ap" (so dest and src are swapped as in strcpy). See here for the man page:

        http://linux.die.net/man/3/va_copy

Since "ap" is a parameter to the function, it is assumed to be initialized.
And - after above line - P.ap is also supposed to be initialized.

Since the source code in question is compiled in C89 mode on some platforms,
there's a module with a replacement va_copy for these platforms. But on all
others a working va_copy is expected, otherwise you will get

    /* If va_copy is not defined now, we have a problem */
    #if !defined(va_copy)
    #error "Need a working va_copy!"
    #endif

So there are several possibilities:

    1. The compiler has va_copy

    2. The compiler doesn't have va_copy, but one is defined in va_copy.h
       (this is the case for gcc and watcom c)

    3. you will get a compile error from va_copy.h

Since you're not getting the error from 3., and you're not using one of the
compilers from 2., only 1. can be true. And if this doesn't work, then the
va_copy that comes with your compiler must be broken.

Regards


        Uz


-- 
Ullrich von Bassewitz                                  uz@musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Sat Mar 23 23:39:54 2013

This archive was generated by hypermail 2.1.8 : 2013-03-23 23:39:58 CET