I have a Visual Studio 2012 solution containing several projects, some in C and some in Fortran (using Intel Composer XE 2013). I frequently call from the Fortran code into the C code using the iso_c_binding utility, but I've noticed that I cannot debug the C code effectively. While debugging the Fortran code, I can view the contents of variables just fine, but if I step into the C code, suddenly they lose their sanity. Most variables just claim to be undefined; anything passed to the function will contain incorrect values (but it still does differentiate between pointers and objects/POD).
I can still step through the code; it seems to mostly follow the expected sequence of execution, but sometimes it does jump around a bit, which I'm familiar with from debugging compiler-optimized code on Linux with gdb.
I have a separate solution that also has C and Fortran projects. Both call into the same C project from the first solution, and in both cases, I can again debug successfully until I step into the C project from the first solution, at which point I have the same problems.
What am I doing wrong?
This is the standard bat signal for debugging code that was optimized. You'll need to rearrange you build settings so your Fortran code links to the non-optimized Debug build of the C code.
There are no breadcrumbs in your question as to how that went wrong in the first place. Start by checking which library is getting linked into your Fortran program and make sure that you can see distinct libraries generated for your C project in the Debug and Release builds. You need to link the one created by the Debug build.