delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2014/03/03/18:09:58

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:mime-version:in-reply-to:references:date
:message-id:subject:from:to:content-type; q=dns; s=default; b=KR
9ngm105Zd7R+eVkUj/9tk250KVGh88CSnDkwRLGdQKwy78hcl/7o5xrbNycPH9km
50zJZIX8a7igCU4jsKQPPMLDFHHRIwv6ruRaGBXMKzdfteQYWUEM+qBOoAIpUSuH
bxkgwFMPHPCwVPlWET43pahUFZwFlVW5rWjAf+0zw=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:mime-version:in-reply-to:references:date
:message-id:subject:from:to:content-type; s=default; bh=i7wzWu0G
D7EedRUicZ2xoHV84Ww=; b=iJQIJlgtzdJ0iZ3owMO7YGk20kpnalwpxWGdVIYt
XGMJVSU1tghsRJem13awetAQ6+0GtLS6Gti+CoqpDzaWXHahwT4ykktMxQpDAYiY
hO9J/qkb/sveIj9H0LXJTf9EdNrdncmc6aW6FhpiQIoU1TBBtHz5A/iti6rJZfJh
eXs=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-0.1 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2
X-HELO: mail-ob0-f175.google.com
MIME-Version: 1.0
X-Received: by 10.182.29.98 with SMTP id j2mr29199424obh.30.1393888178949; Mon, 03 Mar 2014 15:09:38 -0800 (PST)
In-Reply-To: <CAEwic4YmZc8tJN5f1tFEddtk2Yw6731zMcNLNr-=c4=BbRLE9w@mail.gmail.com>
References: <CAJoYywUaRcCx4sQ0j_HZZ77urmPjg19fPP=KuM1d8i8Ec3mmWQ AT mail DOT gmail DOT com> <CAJoYywWOHqh9qpFg3skt9XJFVoYgpa0C=g+g6mtEATiArLbgLg AT mail DOT gmail DOT com> <5313A789 DOT 2080205 AT gmail DOT com> <CAJoYywV7O5EWvtK5oWzgOSK=BrNk+WtSUtYiS4SebHhK-kD0dw AT mail DOT gmail DOT com> <CAEwic4YmZc8tJN5f1tFEddtk2Yw6731zMcNLNr-=c4=BbRLE9w AT mail DOT gmail DOT com>
Date: Tue, 4 Mar 2014 00:09:38 +0100
Message-ID: <CAJoYywUtzsdDqoT5m7anJkd6rOZ-EsESoKun1G5F9FAffntFyQ@mail.gmail.com>
Subject: Re: va_list and char* are ambiguous
From: Irfan Adilovic <irfanadilovic AT gmail DOT com>
To: cygwin AT cygwin DOT com
X-IsSubscribed: yes

On Mon, Mar 3, 2014 at 1:47 PM, Kai Tietz wrote:
> Hi,
>
> cygwin64 shares for 64-bit the ABI of Windows native.  This is caused
> by different reasons (eg. unwind-table description for prologue, etc).
> So for Windows targets va_list is indeed of 'char *' type.  And this
> is ok.  The variant of x86_64 abi, which uses indeed a
> structure-variant for variadic-arguments plus some call-abi
> extensions, isn't recommented for on Windows.  If your linux code
> relies on structure-variadic x86_64-ABI, it seems to me broken, and
> needs to be ported.
>
> Hope this answers your question.
>
> Regards,
> Kai

I will take that as a negative answer to modifying the internal
definition of va_list...

In case anyone else googles this problem and finds this thread: my
main problem was to make string literals be matched against the
ellipsis overload, and not the va_list overload, when the two are
available. Apparently, gcc is too smart for its own good (perhaps
mandated by the standard) and will always automatically remove the
constness of a string literal and select the va_list overload (and
warn you about it!). I found three solutions, both of which require
modifications of affected code.

1) don't overload, rename one of the functions -- may affect much more
code than what is affected by the original problem.
2) cast your string literal to (void *) -- a bit confusing, and causes
a warning if __attribute__ ((format (printf, ...))) is used.
3) introduce a temporary const char *tmp = "string literal" and pass
that. gcc won't try to cast away the constness of a variable and will
match the ellipsis.

Code example:

#include <cstdarg>
#include <iostream>
using namespace std;
void foo (...)        { cout << "varargs\n"; }
void foo (va_list ap) { cout << "va_list\n"; }
int main () {
    foo ("");                       // va_list
    foo ((const char *)"");         // va_list
    foo ((const char *)NULL);       // varargs
    foo ((void *)"");               // varargs
    foo ((const char *)(void *)""); // va_list
    const char *bar = "";
    foo (bar);                      // varargs
}

-- Irfan

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019