0

consider the following simple code. I'm trying to assign an array with variable size "size" entered by the usr. the code "behaves" with expected results.

however, if I try to view the value of array in gdb (using eclips) I get [0]. trying to display it as an array (using the expression (*array@size) or even manually right clicking on array in variable window and ask to "display as array" i get an error: "Can't take address of \"array\" which isn't an lvalue."

If i now change the assignment to be with fix size (e.g. int array[6];) everything works OK including proper display in gdb

any ideas?

int main(void) {
    int size;
    puts("Enter size of array:\n");
    scanf("%d",&size);
    int array[size];
    for (int i=0;i<size;i++) {
    array[i]=i;
}
3
  • Your code snippet misses a closing brace and any relevant #includes.
    – alk
    Mar 29, 2015 at 11:26
  • Doing p *array@size inside gdb (run form the commad line) works for me.
    – alk
    Mar 29, 2015 at 11:30
  • Thanks alk. My code has all relevant #includes and also the closing brace. Digging some more into it, I saw that in the variable length case, the debug error message also says that the value of array was "optimized out" which is strange as I set -O0 flag. I also tried declaring the array with "Volatile" and stil get the optimized out message. Any idea. Forgot to mention I'm running eclips on OS X if it makes any difference
    – NB111
    Mar 29, 2015 at 19:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.