Issues with Keil, C++ and C99 mode

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
RallyTronics
Posts: 3
Joined: Thu Sep 10, 2015 9:24 pm

Issues with Keil, C++ and C99 mode

Post 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?
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

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

Post 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
Post Reply