AnsweredAssumed Answered

Cross-core embedded studio- base constructor va_args implementation

Question asked by bachabharat on Oct 7, 2016
Latest reply on Oct 17, 2016 by Kader.M

I am using cross-core embedded studio 2.3.0 and couldn't get the right sum for the following snippet. But whenever I try to create the base class object code functionality is proper. This code architecture is working good in visualDSP++ and all other compilers like LLVM, GCC, Visual Studio.

 

When I stepped through the disassembly, a intermediate sub object is being created for the derived class constructor which is calling derived class constructor and the va_args is pointing to the stack frame created by the intermediate sub-object which doesn't push the arguments onto the stack and result is not what we expect.

#include <stdarg.h>
#include <stdio.h>int sum = 0;class test{public:    test(int a, ...)    {        va_list temp;        sum = a;        va_start(temp, a);        sum += va_arg(temp, int);        sum += va_arg(temp, int);        sum += va_arg(temp, int);        sum += va_arg(temp, int);        sum += va_arg(temp, int);        va_end(temp);    }};class base_test : public test{public:    base_test(int a, int b, int c, int d, int e, int f) : test(a, b, c, d, e, f)    {    }};void main(){    base_test a(6,5,4,3,2,1);
    printf("Sum: %d",sum);}

Attachments

Outcomes