One time I was working on a college assignment and there was a bug in the school-provided starter code caused by it assigning a pointer to:
char * chr_ptr = "string literal here".c_str();
Turns out that because it's just a string literal and not a "real" string bound to a variable, the C++ compiler just DGAF, lets the pointed-to addresses get filled with random other data, and gives absolutely no errors or warnings.
Spergs on StackOverflow were ripping on me for suggesting this was a bug with the compiler. Oh no, I didn't know this one weird quirk in C++ compiler data memory allocation and scope, I'm soooooo stuuupid.
30
u/GenTelGuy Apr 12 '19
One time I was working on a college assignment and there was a bug in the school-provided starter code caused by it assigning a pointer to:
Turns out that because it's just a string literal and not a "real" string bound to a variable, the C++ compiler just DGAF, lets the pointed-to addresses get filled with random other data, and gives absolutely no errors or warnings.
Spergs on StackOverflow were ripping on me for suggesting this was a bug with the compiler. Oh no, I didn't know this one weird quirk in C++ compiler data memory allocation and scope, I'm soooooo stuuupid.