From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x135.google.com (mail-il1-x135.google.com [IPv6:2607:f8b0:4864:20::135]) by sourceware.org (Postfix) with ESMTPS id 178BB3858002 for ; Thu, 18 Mar 2021 15:25:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 178BB3858002 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=moxielogic.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=green@moxielogic.com Received: by mail-il1-x135.google.com with SMTP id h1so5224336ilr.1 for ; Thu, 18 Mar 2021 08:25:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=moxielogic-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=yqRXYK/3CZCyHraC9zmwwNnLvJbmNrLC+NG1upwYV/c=; b=lLD537ZwKnsuQSXwl5mmHO1uOS6TkobedXK0bcUqiWfaaW25SXsOcRbg9B0/qfc9O4 Iiih+lPXK3B1yXm6UkvvTYdJy9skTxjPz9eG2uYe/1hx8itqgvIW0d7Ka4iJCf10hQr5 Ht67G07Tcr/XHGbBoxK2DGVDIeRFeXNtjsJh+Emnb4Ygpj+Mqq98ke71ZN5r95GvgrQD YPFeDZai/2obR6h1FGgP9PNuffIB7FW6YZt95N6WF78wBTUMzZjPZbrz8suvy61eGuoz Hv79t0eYFDdNQo616EaUs6QFHVnNKmeQYB0XhTbbqy0aJkl6iQ3MoLUhW2KYcQQR5poH 97mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=yqRXYK/3CZCyHraC9zmwwNnLvJbmNrLC+NG1upwYV/c=; b=Vlev1NARsZm9zCgD7kwNBYVUkquPJBgOI8YWFbu/1U21b8KhJodt3TEjEXibJeH/1H G2pIEJ8l74bYps4gCzW1ej5PpAI/wUHR0nzbbEw8EWl+p5EsfogblbiOixocHv98ceaH aBa3rdkiI6koQ+ZpqcvkNu7v+EuNwayxyo5EKP6tSfBG4FYZYg7+fEHDYmzUgD2lEIOP DK7LVWu07Ll5+C+MwbkOegMVEWm6vaYyJ6zpIlMG4EJ2SRSR5r/lG2kG+0uyDZGWcJBX zkW+KdPU1sEXX9K8QPeA6DP4B7DR+d44tBxVoHmtBycgZoxzK/wkjpqdVd3xJN9I5usI MX1Q== X-Gm-Message-State: AOAM532MiCfr0L+n713fbNxCWLoUJalMtRsa2Mpf0skP3YY48Zxhm9X/ b6TBGpS0EQK1kqaekNUBbscWXDeZEj5s6XpKZCZLArikZPWiEwHt X-Google-Smtp-Source: ABdhPJxzgCjmQqntVa2zFrJrxI+2JKCqF+E4lVaEAjumrad80WW+KK6L1RNgfNnV/r0OIfSd/3FBHJF8kPI4NBeKfJ4= X-Received: by 2002:a05:6e02:506:: with SMTP id d6mr11729847ils.150.1616081112042; Thu, 18 Mar 2021 08:25:12 -0700 (PDT) MIME-Version: 1.0 References: <00aed94e-6f76-f6d7-9878-a3eb50dce543@163.com> In-Reply-To: <00aed94e-6f76-f6d7-9878-a3eb50dce543@163.com> From: Anthony Green Date: Thu, 18 Mar 2021 11:25:01 -0400 Message-ID: Subject: Re: How to call 'printf' using libffi? To: ShaJunxing Cc: libffi-discuss X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: libffi-discuss@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libffi-discuss mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Mar 2021 15:25:14 -0000 Here's an example: #include #include int main (void) { ffi_cif cif; void *args[4]; ffi_type *arg_types[3]; char *format = "%.5g, %d\n"; double doubleArg = 3.14159; signed int sintArg = 7; ffi_arg res = 0; arg_types[0] = &ffi_type_pointer; arg_types[1] = &ffi_type_double; arg_types[2] = &ffi_type_sint; arg_types[3] = NULL; /* This printf call is variadic */ ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 3, &ffi_type_sint, arg_types); args[0] = &format; args[1] = &doubleArg; args[2] = &sintArg; args[3] = NULL; ffi_call(&cif, FFI_FN(printf), &res, args); return 0; } On Thu, Mar 18, 2021 at 10:04 AM ShaJunxing via Libffi-discuss < libffi-discuss@sourceware.org> wrote: > 'printf' not only has variable length arguments (maximum length is > unlimited?), but also each argument type may be different. I searched > the whole Internet but still found nothing, anybody help? thank you very > much. > > >