This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software: TI C/C++ Compiler
Hello,
I have some problem with a missing error the compiler shall issue.
We are using CGT version 7.4.23 with CCS 8.1.0.11 on a C6418.
When I was debugging I found out that a constructor of an class is called where no instances should exist.
The class was defined like this
in .h file:
class A
{
static A _instances[];
}
in .cpp file:
A A:_instances[APP_DEFINE_A_INSTANCE_CNT];
For the application I was compiling APP_DEFINE_A_INSTANCE_CNT was set to 0.
Inside of the constructor only member vars were set.
Before main() is reached all static objects are initialized. Therefore the constructor was called. But since no instance was existing, it was overwriting some other data.
What is the reason I don't get the compiler error?
Is it a wrong CGT configuration?
I also tested:
int a[0];
But this is compiled without error, too.
I need your help. I expect to get a compiler error. Is this assumption wrong?
Thank you for your help!
Kind Regards
Bernhard Seiz
Hi Tom,
thanks for your response!
From the wiki
the C6000 version 7.4.23 compiler uses C++03.
Yes I am sure that it was overwriting other data. I started debugging to find a misbehaviour of my application. Then I saw that a global variable that is initialized durind declaration, was overwritten somewhere. It is never touched in our code. So I set up a hardware watchpoint for write access and found the constructor of a class which instances were defined in an array of size 0. In the constructor a value 0 was assigned to a member var. This member var address (Expressions View) was at the same address of my global variable.
I realized that I have enabled the
--relaxed_ansi
compiler switch
does this have an effect?
Bernhard
Dear Tom,
I appreciate any comment! Thanks!
There is always a chance to change the point of view what can lead to other questions that solve an issue.
Hope you progress on your issue.
Bernhard
When I try to compile code similar to ...
Bernhard Seiz said:in .h file:
class A
{
static A _instances[];
}
in .cpp file:
A A:_instances[APP_DEFINE_A_INSTANCE_CNT];
For the application I was compiling APP_DEFINE_A_INSTANCE_CNT was set to 0.
... or ...
Bernhard Seiz said:int a[0];
I always get an error diagnostic similar too ...
"file.cpp", line 6: error: the size of an array must be greater than zero
To understand what happened, I need a test case which allows me to reproduce the same behavior. Please submit a test case as described in the article How to Submit a Compiler Test Case.
Thanks and regards,
-George
Dear George,
I sent you a test case a moment ago. I was following the instruction you provided a link to.
Sorry for the delay, I was very busy.
Looking forward to your feedback
Bernhard
Edit:
I added a line
int a[0];
to the file to trigger the compiler error.
You use the build option --relaxed_ansi . When this option is used, zero length arrays are allowed. The only way to get an error diagnostic is to remove --relaxed_ansi.
Thanks and regards,
-George
Dear George,
thank you very much! You're right.
I could have tested before. Sorry for that.
Kind Regards
Bernhard