Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
IAR compiler bug test code
#include <cassert> #include <cstddef> #include <cstdio> bool functionToTestInitializationBug() // returns 'true' if the bug was detected { static char aStaticLocalVar = 0; struct testStruct { int anInt; char *aPtrToAChar; }; static testStruct testArray[] = { { 0x11111111, NULL }, { 0x22222222, NULL }, { 0x33333333, (char*)0x0a0b0c0d }, { 0x44444444, &aStaticLocalVar }, { 0x55555555, (char*)0xaabbccdd }, { 0x66666666, NULL }, { 0x77777777, NULL }, }; ++aStaticLocalVar; // prevent optimizer from deciding 'aStaticLocalVar' is unused (probably not necessary) return (aStaticLocalVar == 0) // prevent optimizer from deciding 'aStaticLocalVar' is unused (probably not necessary) || (testArray[3].aPtrToAChar != &aStaticLocalVar); // do the actual bug detection } int main() { bool testResult1 = functionToTestInitializationBug(); bool testResult2 = functionToTestInitializationBug(); assert(!testResult1 && !testResult2); printf("No bug.\n"); }
run
|
edit
|
history
|
help
0
Chinu
TempQuickDoubArray2
Test 8(2020)
CPP - Ex 5
NameTempSpecial2
CV
Org
Menu Combination Sum
LRUCache
Exempel 4