GCC for Renesas RX toolchain issue

Hello All,

I am trying to test the below mentioned code snippet, on e2 studio using rx-elf-gcc toolchain for rx65n target

rx-elf-gcc Compiler output is different from gcc output

Code Snippet:

#include <stdio.h>

typedef void (*numentry_t)(int cnt, int arg1, ...);
typedef void (*numentry1_t)(int cnt, int arg1);
struct varargs_s
numentry_t func; /* Function to execute when delay expires */

struct varargs_s vararg;
void test_varargs(int count, int arg1)
count = arg1;
printf("Count value is %d", count);
int varargs_assign(numentry_t varentry)

vararg.func = varentry;
(((vararg.func)))(1, 100); /* 2nd parameter value 100 is not passed to the called function test_varargs */
((numentry1_t)(vararg.func))(1, 100); /* 2nd parameter value 100 is passed to the called function test_varargs correctly */
int main()
return 0;

In function, varargs_assign(), when (((vararg.func)))(1, 100) is called,
2nd arguement for function test_varargs() is not passed as 100.

I also observed that, when (vararg.func))(1, 100) is typecasted to take
2 arguments, the 2nd argument is passed correctly to test_varargs().

Can anyone please suggest what compiler options (CFLAGS), need to be updated,
to get correct value for 2nd argument in function test_varargs without typecasting




  • Good day, Anjana!

    How are things going so far? Have you resolved this issue already?

    Best regards.

    RenesasRulz Forum Moderator
  • Hello,  Anjana.

    You should visit GNU Tools forum or post a support query there to know about details of the compiler:

  • Anjana,

    Has your question been answered?

    Mike Clements
    RenesasRulz Moderator
  • This is not how C variadic functions work.  Your varargs_s struct has a variadic function pointer as a member; you can't call that variadic function pointer like a regular C function.

    static int varargs_assign(numentry_t varentry)
        vararg.func = varentry;
        (((vararg.func)))(1, 100); /* 2nd parameter value 100 is not passed to the c
        ((numentry1_t)(vararg.func))(1, 100); /* 2nd parameter value 100 is passed t

    Your first call to vararg.func() is essentially a lie; you didn't pass a variadic function to varargs_assign(), you passed a function with a fixed number and type of arguments.  Because vararg.func is a variadic function pointer, you also can't call it like a normal C function.  There's no way for the C compiler to know how many arguments the function pointed to by vararg.func actually takes, so it can't correctly construct the call to the function.

    I started to try to modify your program to work with <stdarg.h> macros for handling variadic functions, but I don't know enough about your actual use case to do so.  it sounds like you're trying to store a pointer to a function which may have multiple argument signatures; if so, then a variadic function is not the way to do it.  C doesn't work like that.  In that case, you might simply store the function pointer in a void pointer variable along with a discriminator to select the type of the variable (this is roughly how variadic functions and the stdarg.h macros work).

    If you provide more detail about what you're trying to do, then I can probably provide more assistance.