From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8585 invoked by alias); 21 Jul 2005 22:52:09 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 8563 invoked by uid 22791); 21 Jul 2005 22:52:00 -0000 Received: from wproxy.gmail.com (HELO wproxy.gmail.com) (64.233.184.199) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Thu, 21 Jul 2005 22:52:00 +0000 Received: by wproxy.gmail.com with SMTP id i21so135900wra for ; Thu, 21 Jul 2005 15:51:59 -0700 (PDT) Received: by 10.54.36.8 with SMTP id j8mr798469wrj; Thu, 21 Jul 2005 15:51:29 -0700 (PDT) Received: by 10.54.92.6 with HTTP; Thu, 21 Jul 2005 15:51:29 -0700 (PDT) Message-ID: <623f4f4005072115517ba942df@mail.gmail.com> Date: Thu, 21 Jul 2005 22:52:00 -0000 From: Jean-Sebastien Legare Reply-To: Jean-Sebastien Legare To: gcc-help@gcc.gnu.org Subject: Constructing function calls Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-SW-Source: 2005-07/txt/msg00228.txt.bz2 Hi I have a special task I would like to accomplish regarding construction of function calls, without (preferably) using __asm__ sections. I would like to pass a block of data containing arguments to a function from which I don't know the type nor number of arguments. The only thing I know= =20 is the address of the function pointer and the size of the argument block (number of 32bit words). That is, I would like to fill this function: void call_func( (void*)func(), void* args, int size) { 1. push the contents of args to the stack; 2. call func() with no args (func will recuperate them from the stack); 3. return } For instance, I would like to be able to call : void print3ints(int a, int b, int c) { printf(" %d %d %d\n",a,b,c); } by doing : { int* args =3D malloc( 3 *sizeof(int)); args[0] =3D 1; args[1] =3D 2; args[2] =3D 3; call_func(print3ints,args,3); } I looked at "__builtin_apply" but it requires calling "__builtin_apply_args" beforehand, which I cannot do. I successfully managed to do that without using __asm__ on a x86.=20 I filled a local int array in call_func with the passed argument block and = then=20 I called the passed function (stack bashing). However, the method breaks when compiling in -O3 mode and it would certainly not work on other systems where some arguments are passed inside registers. What are my best options ?