Skip to main content
GameDev.net gamedev.net
🔒 Locked

pointer nonsense

Started by supagu Aug 31, 2003 at 9:46 AM 1 replies 400+ views
Original Post
supagu
supagu
this is what im trying to achive:
// SOME CODE FROM INSIDE SOME FUNCTION:
const char* profileOpts[] = 
    {
        "-profileopts", "dcls", NULL,
    };

newShader.shader = cgCreateProgramFromFile( *Direct3D::GetCgContext(),
CG_SOURCE,	                                         actualPath,	                                              Direct3D::GetCgFragmentProfile(), 
"main",
profileOpts    );
   
now here is a function i have created, and it shows this funciton used to achive the same result as above:
const char** Direct3D::GetCgCompileOptions()
{
	const char* profileOpts[] = 
    {
        "-profileopts", "dcls", NULL,
    };

	return profileOpts;
}

// SOME CODE FROM INSIDE SOME FUNCTION:
newShader.shader = cgCreateProgramFromFile( *Direct3D::GetCgContext(),
CG_SOURCE,	                                         actualPath,                                           Direct3D::GetCgFragmentProfile(),
"main",
Direct3D::GetCgCompileOptions()   );
  
now, the above piece of code works, the bottom doesnt, but when i print both to file, i get the same strings, so i know it should be working... :-/ i'm stumped [edited by - supagu on August 31, 2003 10:48:07 AM] [edited by - supagu on August 31, 2003 10:49:35 AM] [edited by - supagu on August 31, 2003 10:49:58 AM]
superdeveloper
superdeveloper
You are creating the char string within the method, but when you exit, the string is DESTROYED. although you try to return the string, it actually becomes a stale pointer since the method is exited...

THe string is created on the stack, and is exterminated (popped) once you leave the function, try using "new" to create the string as a dynamic object, this will help you.

www.cppnow.com
Shannon Barber
Shannon Barber
Return a std::string instead.
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.