问题
I am attempting to initialize an array with a size of ceil(buflen/125.0) as follows:
long long maxjpg = ceil(buflen/125.0);
long long arr[maxjpg];
I do not receive a compiler error, but GDB reports "no symbol 'arr' in current context". The only fix I have found is by hardcoding a numerical value into the array size like so:
long long arr[5];
I have tried casting, using different variable types, using const
and any combination of these approaches. I know that ceil returns a double
, I have tried working with that too.
Initializing a value and printing it like so works:
arr[0] = 25;
printf(pos 0 is %d\n", arr[0]);
output: pos 0 is 25
Printing arr[0]
through GDB after that modification results in "value has been optimized out".
Minimum viable code to reproduce:
#include <math.h>
int main(void){
long long size = ceil(123.45);
long long arr[size];
return 0;
}
GDB Fedora 7.4.50.20120120-52.fc17
回答1:
VLAs do not currently work in gdb. There's a bug open about it and an ongoing project to fix it: https://sourceware.org/gdb/wiki/VariableLengthArray
There's an implementation in archer.git that works in some cases, but it isn't considered good enough to go in trunk.
来源:https://stackoverflow.com/questions/19116709/gdb-reports-no-symbol-in-current-context-upon-array-initialization