Hallo,
I'm developing a project for i.MX RT 1024 and I have a compiler problem.
I have two pointers to different memory locations. In these location I have the same value. The compiler forces the pointers to point the same location.
I need that the two pointers address must different.
In MCUXpresso I added the falg "-fno-merge-all-constants" in "Other Optimization flags" field of "MCU C Compiler->Optimization", but it hasn't solved the problem.
Many thanks in advance for you support.
Can you show us how the pointers and what they point at are defined, please?
Is there anything going on with the Linker Script for these two memory sections?
Hello,
I created two global pointers like these
char *pA = "123";
char *pB = "123";
I expeted that pA != pB, but pA == pB (because of the compiler optimization they pointer to the same memory area).
I'm using MCUXpresso 11.5 version.
The memory area for "123" value can be RAM or FLASH.
Many thanks.
Kinds Regards.
Hello,
I suggest two ways to do that.
char tempBuffer[3];
char* pA = &tempBuffer[0];
/*or using the standard c library stdlib.h*/
char* pB = (char *) malloc(3);
I hope this helps you, if not tell me for more information.
Best regards,
Pavel
Hello,
the problem is that I'm working with an old project for kinetis K60 and developed using "CodeWarrior 10.6". In that case there wasn't the problem.
Now I have take this project and adapt it for IMXRT 1024. I changed the IDE (now is MCUXpresso 11.5.0) and I saw the situation that I described in the previous posts.
I can not search for all pointers that have in the project with this problem and modify them. So I'd like find a solution like disable the compiler optimization. Is it possible to follow this way?
Many thanks.
Kinds Regards.
What is the optimization level set at now?
-O is what controls the optimization level. If fiddling with that makes the code work, then there is usually something wrong with the code. Static Analysis with something like Lint would find the issues.
-O0 turns off all optimizations. -O2 is generally safest option. -O3 can be aggressive.
-Os for 'small' can also be aggressive in removing code that really might have been expected to stay like busy loops.
-O2 / 3 and -Os implicitly enable Strict Aliasing. Try turning that off:
-fno-strict-aliasing
Turing off all optimizations can make code size explode and create other problems.
Hello,
About the optimization that I'm using, please refer to the file enclosed.
I tried to deselect the "Merge Identical constants" field without any result.
Many thanks.
Kinds Regards.
The image shows that optimization is already turned off.
So the problem is not optimization.
Unless the project was not 'cleaned' when changing these settings.
Always force a full project clean when changing these.
Try adding:
-fno-strict-aliasing
I don't expect it to change anything if optimization is already off.
There is something else going on here.