NO

Author Topic: string value not visible in debugger (compiler optimization)  (Read 2411 times)

Franzki

  • Guest
string value not visible in debugger (compiler optimization)
« on: March 13, 2011, 02:06:03 AM »
See the attached code sample.

In the function "clear_string" I can't watch the value of the string "text" when I switch off optimization.
Flags are: -Tx86-coff -Zi -Ob1 -fp:precise -W1 -Gd

I'm always in doubt what optimization I should use for debugging purposes... I thought all variables should be visible with optimization turned off.

???




Code: [Select]
#include <string.h>
#include <stdio.h>

void clear_string(char * text)
{
strcpy(text,"");
printf("string cleared!\n");
}


int main(void)
{
char text[100];

strcpy(text,"This is a test");
printf("old string: %s\n",text);
clear_string(text);
printf("new string: %s\n",text);
return(0);
}

Offline AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: string value not visible in debugger (compiler optimization)
« Reply #1 on: March 14, 2011, 08:27:17 AM »
I'm always in doubt what optimization I should use for debugging purposes... I thought all variables should be visible with optimization turned off.
Usually you should debug a program without optmization. In your case I think it is an error in the debugger, so that it don't see the variable text.
best regards
 Alex ;)