Thread: problem with MSVC++ 6's release mode

  1. #1
    Registered User dirkduck's Avatar
    Join Date
    Aug 2001
    Posts
    428

    problem with MSVC++ 6's release mode

    Hellow everyone. The problem im having is, when I set the active configuration on my project to 'release', it compiles fine, but when run, gives me an 'illegal error' and quits. The strange thing is that it works perfectly fine when I use it in debug mode. I commented out lines, and have found that in release mode the program goes until it hits this line:

    Code:
    source.getline(line,256);  //get a line from the file
    I don't see why this line would affect the program in release mode but not debug. Anyone know why? Also, I have MSVC++ 6 with service pack 5 installed. Thanks!

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Are you sure you're not overflowing any buffers? The debug build is alot more forgiving than the release build.

  3. #3
    Registered User dirkduck's Avatar
    Join Date
    Aug 2001
    Posts
    428
    I dont think I am...how would I tell if I was? (probably a stupid question, sorry )

  4. #4
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Make sure you're writing within array bounds.

  5. #5
    Registered User dirkduck's Avatar
    Join Date
    Aug 2001
    Posts
    428
    yeah, I checked, and I am.

  6. #6
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    You're probably going to have to post some code.

  7. #7
    Registered User dirkduck's Avatar
    Join Date
    Aug 2001
    Posts
    428
    Sure. I was just moving some code into finctions and now im getting illegal errors all over the place, so once I get these figured out Ill post some. Thanks.

  8. #8
    Registered User dirkduck's Avatar
    Join Date
    Aug 2001
    Posts
    428
    K, well, I got those other errors ironed out, and now the problem isnt just in release mode. It gives me an illegal error weather im in debug or release. I fixed the one I had before, but now I get the illegal error at the end of main. i.e.:

    Code:
    //this is the end of main()
    cout << "Got to the end of main"<<endl;
    return 0;
    }
    It prints the test 'got to the end of main', so it must be a problem in the return. I did a debug on it and all it gives me is an 'access violation'. Anyone know what a reason would be? Thanks.

  9. #9
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Do you have any classes that manage memory? If so it's probably a destructor that's causing the problem, as this will be called as the object goes out of scope (in this case when main() returns).

  10. #10
    Registered User dirkduck's Avatar
    Join Date
    Aug 2001
    Posts
    428
    Nope, doesnt have any classes or structs. Its just a bunch of functions.

  11. #11
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Code?

  12. #12
    Registered User dirkduck's Avatar
    Join Date
    Aug 2001
    Posts
    428
    K, heres the function that must be causing the problem:

    Code:
    void compile(char *sourcefile, int type)
    {
    
    	char *line=new char;  //get a line from the source file
    	char command[256]={0};  //stores commands found in the line  
    //	int i=0;  //used in various for...loops
    	bool done=false;  //when we exit the loop
    	
    
    	ifstream source(sourcefile);  //file to read from
    	source.close();  
    	ofstream output("output.txt");  //file to write output code to
    	output.close();
    	
    	output.open("output.txt");  //open the output file to write to
    	source.open(sourcefile);  //open the source file to read
    
    	source.getline(line,256);  //get a line from the file
    
    	do
    	{
    		
    
    		
    
    		cout << line<<endl;  //print the line for debug purposes
    
    		//COMMENTED OUT THESE FUNCTION CALLS, IT STILL CAUSES ERROR
    		//SO THE PROBLEM IS SOMEWHERE WITHIN THIS FUCTION
    		//p_start_program(line,type);  //PARSE FOR:  start program
            //p_print(line,type);  //print
    		//p_input(line,type);  //input
    		//if(p_end_program(line,type)==true) 
    		//{
    		//	done=true;;  //end program
    		//	cout << "COMPILER:  finshed with end program"<<endl;
    		//}
    		
    		if(done==false) source.getline(line,256);  //get a line from the file	
    		if(done==false) line=a_remove_space(line);  //remove whitespace from a line
    
    		//JUST HERE TO SHOW THAT IT STILL CAUSES THE ERROR EVEN IF IT ONLY
    		//RUNS THROUGH THE LOOP ONCE
    		done=true;	
    
    	}while(done==false);

    I commented out the other function calls, and it gave me the same error, so it has to be in this function. Thanks

  13. #13
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    >char *line=new char; //get a line from the source file

    Allocates memory for sizeof(char*1).

    >source.getline(line,256); //get a line from the file

    Attempts to write up to sizeof(char*256) into sizeof(char*1) allocated memory.

    You're going out of bounds. Try either -

    char *line=new char[256];

    or

    char line[256];

    or std::string.

  14. #14
    Registered User dirkduck's Avatar
    Join Date
    Aug 2001
    Posts
    428
    Ah, stupid mistake on my part! That fixed it. Thanks for all the help!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MSVC Tutorial problem - Monochrome Palette
    By colinH in forum C++ Programming
    Replies: 4
    Last Post: 10-30-2002, 03:57 AM
  2. Differences in Debug and Release builds in MSVC
    By TravisS in forum C Programming
    Replies: 5
    Last Post: 06-19-2002, 10:40 PM
  3. MSVC and ATL problem
    By Unregistered in forum Windows Programming
    Replies: 1
    Last Post: 01-22-2002, 07:07 AM
  4. getting MSVC out of debug mode.
    By Eber Kain in forum C++ Programming
    Replies: 1
    Last Post: 11-01-2001, 11:52 PM
  5. problem going into mode 13h
    By ArseMan in forum C++ Programming
    Replies: 5
    Last Post: 08-31-2001, 04:53 PM