c++ - Compiler policies on destruction of temporaries -


i've been playing following piece of code. file_string returns temporary string should "live" until end of statement. in visual studio 2008, when use ptempfolder, contains rubbish expected. in linux though, intel compiler 11.0, ptempfolder still points valid string. compilers have different policies regarding destruction of temporaries, kind of eager (visual) versus lazy (intel)? or maybe coincidence?

boost::filesystem wpathtempfolder("/tmp"); const wchar_t* const ptempfolder = wpathtempfolder.file_string().c_str(); // use ptempfolder 

btw, boost filesystem version 2. i've seen file_string being deprecated in boost filesystem version 3. , there new c_str method operates on string&, instead of on temporary string.

/*filesystem 2*/ const string_type file_string() const; /*filesystem 3*/ const string_type&  native() const;  // native format, encoding const value_type*   c_str() const;   // native().c_str() 

likely, string still invalid, happens that section of memory hasn't yet been de-allocated @ operating system level , "happens" work. program exhibits undefined behaviour- includes "may continue work if nothing went wrong". visual studio correct here crash program or pretty anything.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -