The impossible has happened
Dave Higton (1515) 3526 posts |
I’m writing an app in C using the DDE (I think mine is about a year old or just over – reminds me, I must update). There’s a function that I call. I’ve got debug statements in. There’s one immediately before a function call, one immediately after it, and some in the called function, including one immediately before its only return point. The first job that the app does, I can see the statement before the call, the statement before the return, and the statement after the call. The second job that the app does, I can see the statement before the call, the statement before the return, but not the one after the call. The called function seems, from the debug statements that it emits, to work identically and correctly both times. The app doesn’t do its job second time round, but nor does it crash or stiff the machine. I can quit it from its icon bar menu. I don’t know how that’s possible. I had something very much like this many years ago with iyoPhone, which was C/GCC. It’s what eventually stopped me from working on it. |
Rick Murray (539) 13840 posts |
Check your memory allocations and array use, local pointers, etc. All function local stuff is put into the stack frame, so overwriting anything there can have an sorts of weird side effects, including such as chunks of code going missing. It can be a complete 🤬 to debug as the code looks correct, debug (-g) builds work, but regular builds have things that simply shouldn’t be possible going on. (aka Been There, Got the War Wounds) |
Andrew McCarthy (3688) 605 posts |
Sometimes taking a good break can help, you revisit the same thing with a fresh perspective. Similarly asking someone else to take a look. You may have tried this, or already know about it, but there’s a utility on Packman called cppcheck- no silver bullet, but it may spot something. As Rick highlights, and as I’m sure you know, memory bugs, off-by-one errors, and those hiding in plain sight can be the most challenging- keep going! |
Dave Higton (1515) 3526 posts |
Got it. I had got confused about pointers to strings, and was using a char** where a char* would have been correct (and easier). I had managed to copy a string into a pointer instead of a buffer. Goodness knows what it must have overwritten beyond the 4 bytes of pointer. |