Consider the following code:
#include <stdio.h>
#include <ctype.h>
char* Mstrupr(char* szCad);
int main()
{
char szCadena[] = "This string should print well.";
printf("%s\n", Mstrupr(szCadena));
printf("%s\n", Mstrupr("This string should fail."));
return 0;
}
char* Mstrupr(char* szCad)
{
int i;
for (i=0; szCad[i]; i++)
szCad[i] = toupper(szCad[i]);
return szCad;
}
The second call to Mstrupr fails to run correctly on linux as its receiving the string as a literal (and not as a char array). When the complete program is run on gdb it fails as well, but when a breakpoint is added to main and the program is run via gdb's next command, the second string is capitalized and printed. Why? I believe this should not be, but my instructor insists that it's part of gdb's design.