Page 1 of 1

Issues with Keil, C++ and C99 mode

Posted: Thu Sep 17, 2015 10:31 pm
by RallyTronics
I have been unable to get a C++ project to link properly using Keil 5.16a. I suspect it's the requirement to use C99 mode that is causing the problems. It links without errors but does not include all of the code that it should. I have the following test program:

Code: Select all

#include "ch.hpp"
using namespace chibios_rt;

class test_thread : public BaseThread
{
public:
    test_thread(void)
    {
        x = 0;
    }

    virtual void main(void)
    {
        while(1)
        {
            chThdSleepMilliseconds(500);
            ++x;
        }
    }
   
    void set_x(int xx)
    {
        x = xx;
    }
   
private:
    volatile int x;
};

test_thread test1;
volatile int y;

int main(void)
{
    System::init();
   
    test1.set_x(5);
    test1.start(9);
   
    while(1)
    {     
        ++y;       
    }
}


test_thread functions that I don't explicitly call ( like the constructor or main ) don't get compiled in. Functions like set_x that I explicitly call work correctly.

Anyone run into this?

Re: Issues with Keil, C++ and C99 mode

Posted: Fri Sep 18, 2015 8:19 am
by Giovanni
Hi,

Something similar happened to me using GCC a while ago, part of the class is simply discarded for some reason. I don't remember exactly what I did, something like adding a parameter to a method made the thing work but I didn't understand the root reason for the issue.

Giovanni