Thread: [Opentnl-zapdev] compiler depending struct array initialization problem
Brought to you by:
mark_frohnmayer,
s_alanet
From: Norbert H. <nh...@gm...> - 2004-07-25 18:44:13
|
=0D=0AWow. I haven't looked into Zap for a couple of weeks. Awesome home ma= ny features have been added recently. I ran across a compilation problem however. I noticed it, when I was compiling with CodeWarrior. I already mentioned the problem in the other e-mail in [opentnl-general]. Since the same problem occurs when compiling with MCVS++ 6.0, I thought I will mention it in more detail again to [opentnl-zapdev] now: In gameWeapons.cpp, there is the global struct array gWeapons[] which is initialized at the spot: gameWeapons.h: struct ShipWeaponInfo { StringTableEntry name; // Display name of the weapon. U32 fireDelay; // Delay between shots. U32 minEnergy; // Minimum energy to fire. U32 drainEnergy; // Amount of energy to drain per shot. U32 projVelocity; U32 projLiveTime; U32 projectileType; }; gameWeapons.cpp: ShipWeaponInfo gWeapons[] =3D { {StringTableEntry("Phaser"), 100, 500, 500, 600, 1000, Projectile= ::Phaser }, {StringTableEntry("Bouncer"), 100, 1800, 1800, 540, 1500, Projectile= ::Bounce }, {StringTableEntry("Triple"), 200, 2100, 2100, 550, 850, Projectile= ::Triple }, {StringTableEntry("Burst"), 700, 5000, 5000, 500, 1000, 0 }, {StringTableEntry("Mine"), 900, 65000, 65000, 500, 1000, 0 }, {StringTableEntry("Turret"), 0, 0, 0, 800, 800, Projectile= ::Turret }, }; From=20CodeWarrior 8.3 I know that it does not compile it, when an object (like StringTableEntry) is handed over as part of the initialization list. MCVS++ 6.0 seems to have a similar problem with that (VS2003 compiled fine by the way). How about initializating each member of the array through a contructor in the struct. I tried it the following way, which compiled fine on CodeWarrior, VC6.0 and VS2003: gameWeapons.h: struct ShipWeaponInfo { // constructor is needed for array initialization list ShipWeaponInfo( StringTableEntry _name,=20 U32 _fireDelay,=20 U32 _minEnergy,=20 U32 _drainEnergy,=20 U32 _projVelocity,=20 U32 _projLiveTime,=20 U32 _projectileType) :=20 name (_name),=20 fireDelay (_fireDelay),=20 minEnergy (_minEnergy),=20 drainEnergy (_drainEnergy),=20 projVelocity (_projVelocity),=20 projLiveTime (_projLiveTime),=20 projectileType(_projectileType)=20 { }; StringTableEntry name; // Display name of the weapon. U32 fireDelay; // Delay between shots. U32 minEnergy; // Minimum energy to fire. U32 drainEnergy; // Amount of energy to drain per shot. U32 projVelocity; U32 projLiveTime; U32 projectileType; }; gameWeapons.cpp: ShipWeaponInfo gWeapons[] =3D { ShipWeaponInfo( StringTableEntry("Phaser"), 100, 500, 500, 600, 1= 000, Projectile::Phaser ), ShipWeaponInfo( StringTableEntry("Bouncer"), 100, 1800, 1800, 540, 1= 500, Projectile::Bounce ), ShipWeaponInfo( StringTableEntry("Triple"), 200, 2100, 2100, 550, 8= 50, Projectile::Triple ), ShipWeaponInfo( StringTableEntry("Burst"), 700, 5000, 5000, 500, 1= 000, 0 ), ShipWeaponInfo( StringTableEntry("Mine"), 900, 65000, 65000, 500, 1= 000, 0 ), ShipWeaponInfo( StringTableEntry("Turret"), 0, 0, 0, 800, 8= 00, Projectile::Turret ), }; That way, the array gets also initialized at the spot. Also, it seems that zap MSDev 6.0 project hasn't been updated for a while. I had to add: zap\flagItem.cpp zap\flagItem.h zap\footballGame.cpp zap\ftol.h zap\gameObjectRender.cpp zap\gameObjectRender.h zap\goalZone.cpp zap\goalZone.h zap\input.cpp zap\input.h zap\LoadoutZone.cpp zap\move.h zap\private.h zap\rabbitGame.cpp zap\rabbitGame.h zap\retrieveGame.cpp zap\soccerGame.h zap\timer.h zap\UIInstructions.cpp zap\UIInstructions.h to zap.dsp. Regards, Norbert. |