Archived

This topic is now archived and is closed to further replies.

meng_mao

static/extern problem

Recommended Posts

mjpeg.h:

static int framecount = 0;
void Update();
--------------------

mjpeg.cpp:
#include "mjpeg.h"

Update()
{
	framecount++;
}
--------------------

main.cpp:
#include "mjpeg.h"

Problem()
{
	extern int framecount;
	cout << framecount << endl;
	if(framecount == 100)
		stop();
	else
		Update();
}
--------------------
  
We've tried different combinations of modifiers for framecount, but the couting always reports 0. What exactly are we missing about C++? (The actual compiler is embedded Visual C++) [edited by - meng_mao on July 2, 2003 12:57:18 PM]

Share this post


Link to post
Share on other sites

mjpeg.h:

extern int framecount;
void Update();
--------------------

mjpeg.cpp:
#include "mjpeg.h"

int framecount;

Update()
{
framecount++;
}
--------------------

main.cpp:
#include "mjpeg.h"

Problem()
{
cout << framecount << endl;
if(framecount == 100)
stop();
else
Update();
}
--------------------


[edited by - foofightr on July 2, 2003 1:23:40 PM]

Share this post


Link to post
Share on other sites
Variable declarations should be in a cpp file, not a header file.

I stand by my original advice. No static, extern in other compilation units.

Extern is bad style anyway.

Share this post


Link to post
Share on other sites
externs are no different than any other programming tools at your disposal. Use them wisely, and they are beneficial. Use them not so wisely, and they will bite you in the ass.

Share this post


Link to post
Share on other sites