Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. C / C++ / MFC
  3. Is this likely to be a bug?

Is this likely to be a bug?

Scheduled Pinned Locked Moved C / C++ / MFC
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Doug
    wrote on last edited by
    #1

    I have come across what is, I think, a bug with Visual C++ running under Windows NT4. Compiler : Visual C++ 6.0 SP5. Operating System : Windows NT4 Service Pack 6a. My code has the following structure: #include statements using namespace std; int main() { A lot of computations, input & output operations using streams.............. CString file = "c:\\results.txt"; int history = 20; const int calcPeriodHalfhours = 6; ofstream outFile1; outFile1.open(file); for (calcPeriod = 1; calcPeriod < calcPeriodHalfhours + 1; calcPeriod++) { outFile1 << history + calcPeriod; // this is the line that causes the grief. outFile1 << endl; } outFile1.close(); outFile1.clear(); return 0; } If I run the Debug Version of this code, everything is works, and the program exits normally. Under the Release Version (compiled with /O2 /Ob0), the code runs to the end, producing the correct output, but then comes up with the Application Error "The instruction at "0x00418698" referenced memory at "0x0000000b". The memory could not be "read". This is an unhandled Access Violation. Memory is not released to the operating system. If I disable the optimisations (/Od), the code runs fine. If I change the line: outFile1 << history + calcPeriod; // this is the line that causes the grief. to outFile1 << history; // this is the line that causes the grief. or to outFile1 << calcPeriod; // this is the line that causes the grief. the code runs fine as Release Version (compiled with /O2 /Ob0). If I declare the "ofstream outFile1" in the global space instead of in the function space, the code runs fine as Release Version (compiled with /O2 /Ob0). If I run the original code as Release Version (compiled with /O2 /Ob0) under Windows 2000 SP1, the code runs fine. Has anyone come across somethding like this problem before? Please let me know. Thank-you Doug Murray Doug

    M 1 Reply Last reply
    0
    • D Doug

      I have come across what is, I think, a bug with Visual C++ running under Windows NT4. Compiler : Visual C++ 6.0 SP5. Operating System : Windows NT4 Service Pack 6a. My code has the following structure: #include statements using namespace std; int main() { A lot of computations, input & output operations using streams.............. CString file = "c:\\results.txt"; int history = 20; const int calcPeriodHalfhours = 6; ofstream outFile1; outFile1.open(file); for (calcPeriod = 1; calcPeriod < calcPeriodHalfhours + 1; calcPeriod++) { outFile1 << history + calcPeriod; // this is the line that causes the grief. outFile1 << endl; } outFile1.close(); outFile1.clear(); return 0; } If I run the Debug Version of this code, everything is works, and the program exits normally. Under the Release Version (compiled with /O2 /Ob0), the code runs to the end, producing the correct output, but then comes up with the Application Error "The instruction at "0x00418698" referenced memory at "0x0000000b". The memory could not be "read". This is an unhandled Access Violation. Memory is not released to the operating system. If I disable the optimisations (/Od), the code runs fine. If I change the line: outFile1 << history + calcPeriod; // this is the line that causes the grief. to outFile1 << history; // this is the line that causes the grief. or to outFile1 << calcPeriod; // this is the line that causes the grief. the code runs fine as Release Version (compiled with /O2 /Ob0). If I declare the "ofstream outFile1" in the global space instead of in the function space, the code runs fine as Release Version (compiled with /O2 /Ob0). If I run the original code as Release Version (compiled with /O2 /Ob0) under Windows 2000 SP1, the code runs fine. Has anyone come across somethding like this problem before? Please let me know. Thank-you Doug Murray Doug

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      Your EXE's base address is 0x00400000, so something in the EXE is likely dereferencing a null pointer (since the error is coming from an attempted read of address 0xB). Step into the operator<< call and see what happens. --Mike-- http://home.inreach.com/mdunn/ The preferred snack of 4 out of 5 Lounge readers.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups