Click here to Skip to main content
15,903,203 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
int COXEdit::Validate()
{
static CString sFullText;
	int nRet=ValidateInput();

	CString sNewText=GetInputData();
	if ((::IsWindow(m_hWnd)) && (UINT) sNewText.GetLength()>GetLimitText())
	{
		int n=0;
		for (n=0; n<sFullText.GetLength(); n++)
			m_arrInputData.SetAtGrow(n,sFullText.GetAt(n));
		m_arrInputData.SetAtGrow(n,NULL);
	}
	sFullText=COXEdit::GetInputData();
	return nRet;

}	


What I have tried:

What is the purpose of that variable. I can not see anything, and the usage of function local statics causes many problems .. Including (but not limited to immediate crash of the containing program is a control is accessed from outside the default Domain)....
Posted
Updated 6-Feb-23 5:32am
Comments
KarstenK 7-Feb-23 4:01am    
I guess it is a relict from some previous code. Dig into your repo ;-)

I see no useful purpose for that variable to be static. The variable is assigned but never used for anything so I see no purpose for its existence at all. Also, the way it is calling GetInputData is a bit weird because that syntax is usually used for calling static methods.

If I had to deal with that code I would comment off both the declaration of sFullText and the line where it is assigned and see what happens. Unless there are side effects in the GetInputData function, nothing should happen.
 
Share this answer
 
Comments
CPallini 6-Feb-23 13:14pm    
5.
static in C++ means different things depending on where it is used: a static variable inside a function is allocated for the lifetime of the application, and even if the function is called many times the value is preserved. For example, if you initialize a static variable to zero, and treh function increments it each time it is called, then it will retain the value from the previous call acting as a "calls counter" for that function.
If it is declared an non-static, the value is not retained.

In your code, the string is preserved within the function so it "grows" each time the function is called.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900