I'm trying to complete Problem 4 of Project Euler, and I've been trying to debug my solution for quite awhile now. The bug itself isn't part of my question – I can't figure out why GDB won't show me an array value necessary to figuring out the bug.
Whenever gdb reaches this loop,
for (int i = numDigits; i > 0; i--) {
numArray[i-1] = prevPalindrome % 10;
prevPalindrome /= 10;
I am unable to get a value from GDB by the command print numArray
or print numArray[0]
or print numArray[5]
.
GDB instead does the following:
print numArray
returns$1 = <optimized out>
- Both
print numArray[0]
andprint numArray[5]
return `value has been optimized out'
I have already scoured StackOverflow for a way to fix this. I have attempted the following, and none have worked:
- My makefile already uses
-O0
(its command isclang -ggdb3 -O0 -std=c99 -Wall -Werror test.c -lcs50 -lm -o test
), so I tried to use justclang -O0 test.c -lcs50 -lm -o test
. This did not do anything. - I tried using
-0g
, and I got a compiler error. - I tried making the numArray volatile. I got the code to compile, but it was still
<optimized out>
. - I tried TUI mode at the suggestion of @Zan-Lynx, and it was quite cool, but I to be honest I got lost and it was still
<optimized out>
.
Is there something I am missing here? Shouldn't I just be able to print an array value?
The full code is available here, with the loop in question on line 95.