Something stange with a variable

This variable in my program is used to accumulate the size of a folder. As soon as i press F10 to start debug(I use Microsoft Visual Studio), the variable fs (folder size) starts at 2,147,348,480. before i even create and initalize it. Then once i enter an if statement, more specifically;
else if( argc == 2 )

the variable goes to 14,757,395,258,967,641,292...thats just stupid...

I'm using boost and the variable is a boost uintmax_t like so:
boost::uintmax_t fs = 0;

Its late and i can't even sleep because this problem is driving me crazy. Is this just a boost thing, or is there something wrong with the way i coded it, I don't know, any ideas?
Are you debugging without optimizations and compiling with debugging information? If the answer is no to either, the debugger is probably reading wrong memory locations.
Hmm, this might help (I am not a windows programmer).

14,757,395,258,967,641,292 = 0xcccccccccccccccc

Doesn't msoft initialize things to that value in debug builds?
How do i debug with optimizations and compile with debug information? Cuz i'm not sure if i am.
How do i debug with optimizations and compile with debug information? Cuz i'm not sure if i am.


For optimizations, you want them off:
Project -> Properties -> Config Properties -> C/C++ -> Optimization -> Optimization (Turn this OFF)

For Debug Information:
Get to Config Properties -> Linker -> Debugging -> Generate Debug Info (Turn this ON)
Optimization is disabled and Generate Debug info was already on, and i'm still getting the variable fs as 14,757,395,258,967,641,292
Ok found the problem, this code is what calculate the fs variable:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
boost::uintmax_t& scan( path& folder )
{
	boost::uintmax_t fs = 0;
	try
	{
		locale local( "" );
		cout.imbue( local );
		directory_iterator dirIter( folder );
		directory_iterator dirEnd;
		while( dirIter != dirEnd )
		{
			if( !is_directory( dirIter->path() ) )
				fs += file_size( dirIter->path() );
			else
			{
				path next_folder = dirIter->path();
				fs += scan_h( next_folder );
			}
			++dirIter;
		}
		return fs; // warning: C1472: returning address of local variable or temporary
	}
	catch( filesystem_error& e )
	{
		cout << e.what() << endl;
	}
	catch(...)
	{
		cerr << "Error: Found an unexpected error" << endl;
	}
	return fs; // warning: C1472: returning address of local variable or temporary
}


Apparently this warning means i need to return something else other than a local variable from the function. Any ideas?
Last edited on
Return a non-reference, non-pointer.
Return a non-reference, non-pointer


Yup that works, thanks helios
Topic archived. No new replies allowed.