Click here to Skip to main content
15,926,281 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: static variable Pin
User 58385223-Aug-07 20:29
User 58385223-Aug-07 20:29 
GeneralRe: static variable Pin
George_George23-Aug-07 20:31
George_George23-Aug-07 20:31 
GeneralRe: static variable Pin
User 58385223-Aug-07 20:36
User 58385223-Aug-07 20:36 
GeneralRe: static variable Pin
George_George23-Aug-07 20:51
George_George23-Aug-07 20:51 
GeneralRe: static variable Pin
User 58385223-Aug-07 20:55
User 58385223-Aug-07 20:55 
GeneralRe: static variable Pin
George_George23-Aug-07 22:27
George_George23-Aug-07 22:27 
AnswerRe: static variable Pin
ghle24-Aug-07 15:28
ghle24-Aug-07 15:28 
AnswerRe: static variable Pin
ghle25-Aug-07 4:04
ghle25-Aug-07 4:04 
(Surprised) I tried it and it worked. There was no problem accessing the static variable by address outside the function.

Be certain not to in-line the function, as that has certain ramifications.

The static is created on the heap, and the address *is* accessible from outside the class and outside the function it is defined in.

I am quite surprised. I thought even the compiler would catch it. Ignore previous post.Blush | :O


<br />
int *CPBDialog::TryThis()<br />
{<br />
 static int test;<br />
<br />
	test += 1;<br />
	return &test;<br />
}<br />
<br />
<br />
CErrorOkDlg::CErrorOkDlg(CWnd* pParent /*=NULL*/)<br />
	: CPBDialog(CErrorOkDlg::IDD, pParent)<br />
{<br />
	//{{AFX_DATA_INIT(CErrorOkDlg)<br />
	//}}AFX_DATA_INIT<br />
}<br />
<br />
<br />
BOOL CErrorOkDlg::OnInitDialog() <br />
{<br />
	CPBDialog::OnInitDialog();<br />
<br />
	ModifyStyleEx(0,WS_EX_NODRAG,0);<br />
<br />
	// Sound Beeper<br />
	SoundWarning();<br />
	int *test = TryThis();<br />
	int test2 = *test;<br />
<br />
	return FALSE;<br />
}<br />
<br />
<br />


Gary
GeneralRe: static variable Pin
George_George25-Aug-07 22:08
George_George25-Aug-07 22:08 
AnswerRe: static variable Pin
BadKarma23-Aug-07 22:10
BadKarma23-Aug-07 22:10 
GeneralRe: static variable Pin
George_George23-Aug-07 22:36
George_George23-Aug-07 22:36 
GeneralRe: static variable Pin
BadKarma23-Aug-07 23:24
BadKarma23-Aug-07 23:24 
GeneralRe: static variable Pin
George_George23-Aug-07 23:39
George_George23-Aug-07 23:39 
GeneralRe: static variable Pin
toxcct24-Aug-07 1:42
toxcct24-Aug-07 1:42 
GeneralRe: static variable Pin
George_George25-Aug-07 21:25
George_George25-Aug-07 21:25 
GeneralRe: static variable Pin
codeII24-Aug-07 1:49
codeII24-Aug-07 1:49 
GeneralRe: static variable Pin
George_George25-Aug-07 21:27
George_George25-Aug-07 21:27 
AnswerRe: static variable Pin
David Crow24-Aug-07 6:05
David Crow24-Aug-07 6:05 
GeneralRe: static variable Pin
George_George25-Aug-07 21:29
George_George25-Aug-07 21:29 
AnswerRe: static variable Pin
ghle26-Aug-07 3:42
ghle26-Aug-07 3:42 
GeneralRe: static variable Pin
George_George26-Aug-07 6:42
George_George26-Aug-07 6:42 
GeneralRe: static variable [modified] Pin
ghle26-Aug-07 10:00
ghle26-Aug-07 10:00 
GeneralRe: static variable Pin
George_George26-Aug-07 19:22
George_George26-Aug-07 19:22 
Questionregistry cleaner for window xp Pin
niki dutta23-Aug-07 18:26
niki dutta23-Aug-07 18:26 
AnswerRe: registry cleaner for window xp Pin
User 58385223-Aug-07 19:18
User 58385223-Aug-07 19:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.