Using VS2005 and getting undeclared identifier errors.

JayThomas

Warlord
Joined
Apr 10, 2003
Messages
166
Location
Western New York
I'm a little late to the party, but decided to give the SDK a try.

I've eliminated the warnings but kept getting undeclared identifier errors (6 of them, all in CvGame.cpp). This is odd since I have yet to do anything to the code.

Five of the undeclared identifiers were for() indexes and putting the int in the for() made those go away.

The last one is a problem (sorry, can't get the tabs to show up):

Spoiler :

for (int iTeam2 = 0; iTeam2 < MAX_CIV_TEAMS; ++iTeam2)
{
if (iTeam != kPlayer.getTeam())
{
CvTeam& kTeam2 = GET_TEAM((TeamTypes)iTeam2);
if (kTeam2.isFullMember(eVoteSource))
{
if (!kTeam2.isAtWar(kPlayer.getTeam()) && kTeam2.canChangeWarPeace(kPlayer.getTeam()))
{
bAtWarWithEveryone = false;
break;
}
}
}
}


iTeam is undeclared in this scope. It is declared in previous for() loops as an index but is not in scope here.

I can't just declare it since I don't know what value to initialize it to since it is being used in a comparison statement.

I just find it odd that undeclared identifier errors could be generated at this point since no changes to the source have occured except for the project conversion process.

Any ideas?

Thanks
 
It's odd that you have to fix anything in the first place, I can compile the SDK without modification. Are you sure you didn't mix up the SDK files from different versions (vanila, warlords, bts) or modified code?

Anyway, I found the code in the isValidVoteSelection() method:
Spoiler :
Code:
		bool bAtWarWithEveryone = true;
		for (int iTeam2 = 0; iTeam2 < MAX_CIV_TEAMS; ++iTeam2)
		{
			if (iTeam != kPlayer.getTeam())
			{
				CvTeam& kTeam2 = GET_TEAM((TeamTypes)iTeam2);
				if (kTeam2.isFullMember(eVoteSource))
				{
					if (!kTeam2.isAtWar(kPlayer.getTeam()) && kTeam2.canChangeWarPeace(kPlayer.getTeam()))
					{
						bAtWarWithEveryone = false;
						break;
					}
				}
			}
		}
If I use the VS feature 'go to declaration' on iTeam in this code it takes me to: (about 150 lines before your problem code)
Spoiler :
Code:
	int iNumVoters = 0;
	for (int iTeam = 0; iTeam < MAX_CIV_TEAMS; ++iTeam)
	{
		if (GET_TEAM((TeamTypes)iTeam).isVotingMember(eVoteSource))
		{
			++iNumVoters;
		}
	}
It doesn't make any sense to me either. First, being in the for loop should put it out of scope. Second the value of iTeam when used later would always be equal to MAX_CIV_TEAMS - 1, assuming it was in scope, so the code in question is checking if the player's team doesn't equal MAX_CIV_TEAMS - 1. Looks broken to me, maybe try it with iTeam2 instead and see what happens :)
 
Funny, I tried changing it to iTeam2 before, just for grins.
I also declared iTeam and set it to zero.

Both broke the program after selecting Single Player->Custom Game.

Oh well, I'll keep poking around with compiler options.

Thanks.
 
Out of curiosity, have you found that anyone has been able to get the dll to build properly with VS 2005? I read in the SDK thread in the main C&C forum that it only works with 2003 or that other utility they have.

Hoping it does work with '05, because that's what I have!
 
Ok guys, I followed the setup procedure from the link Seven05 posted, and everything compiles fine for me. I also took a look at the code you're having an issue with, and I'm >99.9% ;) sure I know the issue.

Jay, I'm going to guess you didn't follow that post and aren't using the makefile - instead what you did was open the VS6 project in VS8 and try to get it working from the converter. Correct? If so, I'd like to see where you "fixed" the other undeclared identifiers, as I imagine I know a better solution than just placing the "int" before the variable in the loop.

In any case, the code here is correct...sort of. The iTeam variable is declared in the for loop on line 5680:
Code:
for (int iTeam = 0; iTeam < MAX_CIV_TEAMS; ++iTeam)
{
	if (GET_TEAM((TeamTypes)iTeam).isVotingMember(eVoteSource))
	{
		++iNumVoters;
	}
}
And it's used again down on line 6010 in an else if block:
Code:
else if (GC.getVoteInfo(kData.eVote).isForceWar())
{
	CvPlayer& kPlayer = GET_PLAYER(kData.ePlayer);
	CvTeam& kTeam = GET_TEAM(kPlayer.getTeam());

	if (kTeam.isAVassal())
	{
		return false;
	}

	if (kPlayer.isFullMember(eVoteSource))
	{
		return false;
	}

	bool bAtWarWithEveryone = true;
	for (int iTeam2 = 0; iTeam2 < MAX_CIV_TEAMS; ++iTeam2)
	{
		if (iTeam != kPlayer.getTeam())
		{
			CvTeam& kTeam2 = GET_TEAM((TeamTypes)iTeam2);
			if (kTeam2.isFullMember(eVoteSource))
			{
				if (!kTeam2.isAtWar(kPlayer.getTeam()) && kTeam2.canChangeWarPeace(kPlayer.getTeam()))
				{
					bAtWarWithEveryone = false;
					break;
				}
			}
		}
	}
So the natural reaction here is, wtf? That variable's declared in a for loop, it's out of scope!! Well, that's true now, but wasn't prior to a few years ago when the ANSI C standard made it that way (and then a year or two later when the people making compiler libraries enforced it).

Basically, with the VS2003 libs, an integer declared within that first line of a for loop is in scope at the same level that the for loop is run - in this case, above the else if statement. So it's in scope, and perfectly legal, although poor form and illegal with today's standard.

Hope that helps, and I'd definitely recommend using the tutorial that uses the makefile build process, as it worked first time out of the gate for me. You'll have to download & install the VS2003 toolkit and the platform SDK (which takes forever) but it works and you'll be able to avoid compatibility issues like these.
 
Glad it worked for you, fortunately I already had the current platform SDK so it was an easy process for me :)

I also forgot about the older ansi standards for scope, a couple of years is a long time in this inductry. Thinking back it makes perfect sense though.
 
Out of curiosity, have you found that anyone has been able to get the dll to build properly with VS 2005? I read in the SDK thread in the main C&C forum that it only works with 2003 or that other utility they have.

Hoping it does work with '05, because that's what I have!

Trynthlas, using the steps linked in this post (with the bts make file) I am now compiling away using VS 2005 (NOT express).
 
Hehe, yes indeed it does :) I got it working before I posted my earlier response about the issue you were having, as I wanted to see for myself before I pronounced that I knew what was going on...just in case I was wrong or something ;) :p
 
Top Bottom