Skip to content

[ZH] Fix compilation using MinGW #547

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
6b5f516
[ZH] Basic preprocessor fixes
zzambers Apr 1, 2025
176f1ce
[ZH] Replacements of _int64 with __int64
zzambers Apr 1, 2025
5ec2ac7
[ZH] Introdution of CPP_11 macro for code requiring c++11 or higher
zzambers Mar 30, 2025
43c49b2
[ZH] Forward enum declacrations portability fix
zzambers Apr 1, 2025
d89f254
[ZH] Fix of missing forward declarations
zzambers Apr 1, 2025
3c05bd8
[ZH] Fix of missing includes
zzambers Apr 1, 2025
1a37f94
[ZH] Fix of accesses to parent class members
zzambers Mar 29, 2025
3d4c893
[ZH] Fixes of template specializations
zzambers Apr 1, 2025
32c2234
[ZH] Removal of static keyword for enums
zzambers Apr 1, 2025
eaf937e
[ZH] Fixed boolean redefinition
zzambers Mar 29, 2025
f5e72d9
[ZH] Fix of non-static declarations with static definitions
zzambers Apr 1, 2025
862b45d
[ZH] Fix of function pointer catsts to void*
zzambers Apr 1, 2025
337a01d
[ZH] Fix of direct constructor calls
zzambers Apr 1, 2025
d8fb831
[ZH] Fix of unsigned values in signed arrays
zzambers Apr 1, 2025
be8d67b
[ZH] COM related fixes
zzambers Apr 1, 2025
11928ee
[ZH] Fixes of test main methods
zzambers Apr 1, 2025
95e8064
[ZH] Fix to do stack trace only when support is enabled
zzambers Apr 1, 2025
ed1a5dd
[ZH] Fix of unsigned short casts
zzambers Mar 29, 2025
6e6fad4
[ZH] typename fixes
zzambers Mar 29, 2025
81f4234
[ZH] Fix of virtual method declarations
zzambers Mar 29, 2025
4cb8d7c
[ZH] Fix of sizeof operators
zzambers Mar 29, 2025
1073855
[ZH] Fix of forgotten BitTest macro usage
zzambers Mar 29, 2025
ef1d840
[ZH] Fix making use of proper MouseButtonState constants
zzambers Mar 29, 2025
cd6be77
[ZH] Fix to avoid unsupported __try and __except on GCC
zzambers Mar 29, 2025
9edf0f4
[ZH] Fix to avoid VS specific new operators on GCC
zzambers Apr 1, 2025
63ec6dd
[ZH] Fix of loop counter scope
zzambers Mar 29, 2025
aa30755
[ZH] Fix of calls with excess argument
zzambers Mar 29, 2025
23a34a9
[ZH] Removal of duplicit strtrim
zzambers Mar 30, 2025
b117146
[ZH] Fix of strtok_r redefinition on mingw
zzambers Mar 29, 2025
feba1d3
[ZH] Use feature testing macros for std::atomic_flag::{wait,notify_one}
zzambers Apr 1, 2025
c5cc49c
[ZH] Fixes to intrin_compat.h
zzambers Apr 2, 2025
ff2197f
[ZH] Rest of asm code made VC only
zzambers Apr 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Dependencies/Utility/Utility/CppMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,26 @@

#pragma once

#include <cassert>
#define UNIMPLEMEMTED_ERROR(msg) do { \
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UNIMPLEMENTED_ERROR

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I had to read it several times to spot the typo :) I'll fix that.

assert(("Unimplemented: ", msg, 0)); \
} while(0)

#if __cplusplus >= 201703L
#define NOEXCEPT_17 noexcept
#else
#define NOEXCEPT_17
#endif

// noexcept for methods of IUNKNOWN interface
#if defined(_MSC_VER)
#define IUNKNOWN_NOEXCEPT NOEXCEPT_17
#else
#define IUNKNOWN_NOEXCEPT
#endif

#if __cplusplus >= 201103L
#define CPP_11(code) code
#else
#define CPP_11(code)
#endif
28 changes: 16 additions & 12 deletions Dependencies/Utility/Utility/intrin_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ static inline uint32_t _lrotl(uint32_t value, int shift)
#ifdef _WIN32
#include <intrin.h>
#pragma intrinsic(__rdtsc)
#endif

#endif // _WIN32
#endif // _rdtsc
#ifndef _rdtsc
static inline uint64_t _rdtsc()
{
#if _WIN32
#ifdef _WIN32
return __rdtsc();
#elif defined(__has_builtin) && __has_builtin(__builtin_readcyclecounter)
return __builtin_readcyclecounter();
Expand All @@ -82,9 +83,9 @@ static inline uint64_t _rdtsc()
#error "No implementation for _rdtsc"
#endif
}
#endif
#endif // _rdtsc

#ifdef _MSC_VER
#ifdef _WIN32
#include <intrin.h>
#pragma intrinsic(_ReturnAddress)
#elif defined(__has_builtin)
Expand Down Expand Up @@ -113,17 +114,20 @@ static inline uint64_t _rdtsc()
#endif

#ifndef cpuid
#if defined(_MSC_VER)
#if (defined _M_IX86 || defined _M_X64 || defined __i386__ || defined __amd64__)
#ifdef _WIN32
#include <intrin.h>
#define cpuid(regs, cpuid_type) __cpuid(reinterpret_cast<int *>(regs), cpuid_type)
#elif (defined __clang__ || defined __GNUC__) && (defined __i386__ || defined __amd64__)
#elif (defined __clang__ || defined __GNUC__)
#include <cpuid.h>
#define cpuid(regs, cpuid_type) __cpuid(cpuid_type, regs[0], regs[1], regs[2], regs[3])
#else
/* Just return 0 for everything if its not x86 */
#endif
#endif // (defined __i386__ || defined __amd64__)
#endif // cpuid
#ifndef cpuid
/* Just return 0 for everything if its not x86 or as fallback */
#include <string.h>
#define cpuid(regs, cpuid_type) memset(regs, 0, 16)
#endif
#endif //cpuid
#endif // cpuid

#endif // defined(_MSC_VER) && _MSC_VER < 1300
#endif // !(defined(_MSC_VER) && _MSC_VER < 1300)
2 changes: 1 addition & 1 deletion GeneralsMD/Code/GameEngine/Include/Common/AcademyStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ struct AcademyAdviceInfo
UnsignedInt numTips;
};

enum AcademyClassificationType
enum AcademyClassificationType CPP_11(: int)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you specifying the underlying type for enums that are fully defined? Specifying the type is optional?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you use type on forward declarations of enum, you then need to use it also for definitions. Inconsistency here can lead to compiler errors as well.

Copy link
Author

@zzambers zzambers Apr 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the scale of the issue, I have not explicitly checked existence of forward declarations of each enum, but simply changed them all (in GameEngine and GameEngineDevice, by script). I think changing all is better anyway, because in other case you would have some enums you can forward declare and some which you cant...

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with consistency.

{
//Don't forget to update the strings too!
ACT_NONE,
Expand Down
10 changes: 5 additions & 5 deletions GeneralsMD/Code/GameEngine/Include/Common/ActionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@
class Object;
class Player;
class SpecialPowerTemplate;
enum SpecialPowerType;
enum WeaponSlotType;
enum CommandSourceType;
enum CanAttackResult;
enum SpecialPowerType CPP_11(: int);
enum WeaponSlotType CPP_11(: int);
enum CommandSourceType CPP_11(: int);
enum CanAttackResult CPP_11(: int);

enum CanEnterType
enum CanEnterType CPP_11(: int)
{
CHECK_CAPACITY,
DONT_CHECK_CAPACITY,
Expand Down
4 changes: 3 additions & 1 deletion GeneralsMD/Code/GameEngine/Include/Common/AudioAffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
#ifndef _AUDIOAFFECT_H_
#define _AUDIOAFFECT_H_

#include <Lib/BaseType.h>

// if it is set by the options panel, use the system setting parameter. Otherwise, this will be
// appended to whatever the current system volume is.
enum AudioAffect
enum AudioAffect CPP_11(: int)
{
AudioAffect_Music = 0x01,
AudioAffect_Sound = 0x02,
Expand Down
8 changes: 4 additions & 4 deletions GeneralsMD/Code/GameEngine/Include/Common/AudioEventInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@
struct FieldParse;

// USEFUL DECLARATIONS ////////////////////////////////////////////////////////////////////////////
enum AudioType
enum AudioType CPP_11(: int)
{
AT_Music,
AT_Streaming,
AT_SoundEffect
};

extern const char *theAudioPriorityNames[];
enum AudioPriority
enum AudioPriority CPP_11(: int)
{
AP_LOWEST,
AP_LOW,
Expand All @@ -59,7 +59,7 @@ enum AudioPriority
};

extern const char *theSoundTypeNames[];
enum SoundType
enum SoundType CPP_11(: int)
{
ST_UI = 0x0001,
ST_WORLD = 0x0002,
Expand All @@ -73,7 +73,7 @@ enum SoundType
};

extern const char *theAudioControlNames[];
enum AudioControl
enum AudioControl CPP_11(: int)
{
AC_LOOP = 0x0001,
AC_RANDOM = 0x0002,
Expand Down
6 changes: 3 additions & 3 deletions GeneralsMD/Code/GameEngine/Include/Common/AudioEventRTS.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
// forward declarations ///////////////////////////////////////////////////////////////////////////
struct AudioEventInfo;

enum OwnerType
enum OwnerType CPP_11(: int)
{
OT_Positional,
OT_Drawable,
Expand All @@ -47,15 +47,15 @@ enum OwnerType
OT_INVALID
};

enum PortionToPlay
enum PortionToPlay CPP_11(: int)
{
PP_Attack,
PP_Sound,
PP_Decay,
PP_Done
};

enum AudioPriority;
enum AudioPriority CPP_11(: int);

// This is called AudioEventRTS because AudioEvent is a typedef in ww3d
// You might want this to be memory pooled (I personally do), but it can't
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#ifndef _AUDIOHANDLESPECIALVALUES_H_
#define _AUDIOHANDLESPECIALVALUES_H_

enum AudioHandleSpecialValues
enum AudioHandleSpecialValues CPP_11(: int)
{
AHSV_Error = 0x00,
AHSV_NoSound,
Expand Down
2 changes: 1 addition & 1 deletion GeneralsMD/Code/GameEngine/Include/Common/AudioRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

class AudioEventRTS;

enum RequestType
enum RequestType CPP_11(: int)
{
AR_Play,
AR_Pause,
Expand Down
16 changes: 8 additions & 8 deletions GeneralsMD/Code/GameEngine/Include/Common/BorderColors.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ struct BorderColor

const BorderColor BORDER_COLORS[] =
{
{ "Orange", 0xFFFF8700, },
{ "Green", 0xFF00FF00, },
{ "Blue", 0xFF0000FF, },
{ "Cyan", 0xFF00FFFF, },
{ "Magenta", 0xFFFF00FF, },
{ "Yellow", 0xFFFFFF00, },
{ "Purple", 0xFF9E00FF, },
{ "Pink", 0xFFFF8670, },
{ "Orange", (long)0xFFFF8700, },
{ "Green", (long)0xFF00FF00, },
{ "Blue", (long)0xFF0000FF, },
{ "Cyan", (long)0xFF00FFFF, },
{ "Magenta", (long)0xFFFF00FF, },
{ "Yellow", (long)0xFFFFFF00, },
{ "Purple", (long)0xFF9E00FF, },
{ "Pink", (long)0xFFFF8670, },
};

const long BORDER_COLORS_SIZE = sizeof(BORDER_COLORS) / sizeof (BORDER_COLORS[0]);
4 changes: 2 additions & 2 deletions GeneralsMD/Code/GameEngine/Include/Common/BuildAssistant.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ typedef ObjectSellList::iterator ObjectSellListIterator;
//-------------------------------------------------------------------------------------------------
/** Return codes for queries about being able to build */
//-------------------------------------------------------------------------------------------------
enum CanMakeType
enum CanMakeType CPP_11(: int)
{
CANMAKE_OK,
CANMAKE_NO_PREREQ,
Expand All @@ -86,7 +86,7 @@ enum CanMakeType
//-------------------------------------------------------------------------------------------------
/** Return codes for queries about legal build locations */
//-------------------------------------------------------------------------------------------------
enum LegalBuildCode
enum LegalBuildCode CPP_11(: int)
{
LBC_OK = 0,
LBC_RESTRICTED_TERRAIN,
Expand Down
2 changes: 2 additions & 0 deletions GeneralsMD/Code/GameEngine/Include/Common/Debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ DEBUG_EXTERN_C void ReleaseCrashLocalized(const AsciiString& p, const AsciiStrin

#ifdef DEBUG_PROFILE

#include <stdlib.h>

class SimpleProfiler
{
private:
Expand Down
2 changes: 1 addition & 1 deletion GeneralsMD/Code/GameEngine/Include/Common/DisabledTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
/** Kind of flags for determining groups of things that belong together
* NOTE: You *MUST* keep this in the same order as the DisabledNames[] below */
//-------------------------------------------------------------------------------------------------
enum DisabledType
enum DisabledType CPP_11(: int)
{
DISABLED_DEFAULT, //Typical disable -- like systems, things that don't need to run.
DISABLED_HACKED, //This unit has been hacked
Expand Down
4 changes: 2 additions & 2 deletions GeneralsMD/Code/GameEngine/Include/Common/DrawModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class TracerDrawInterface;
class RopeDrawInterface;
class LaserDrawInterface;
class FXList;
enum TerrainDecalType;
enum ShadowType;
enum TerrainDecalType CPP_11(: int);
enum ShadowType CPP_11(: int);

//class ModelConditionFlags;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class DynamicAudioEventInfo : public AudioEventInfo

private:
// List of fields we can override
enum OverriddenFields
enum OverriddenFields CPP_11(: int)
{
OVERRIDE_NAME = 0,
OVERRIDE_LOOP_FLAG,
Expand Down
2 changes: 1 addition & 1 deletion GeneralsMD/Code/GameEngine/Include/Common/Errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
to add to this list as necessary; however, there should generally be very
few codes needed.
*/
enum ErrorCode
enum ErrorCode CPP_11(: unsigned)
{
ERROR_BASE = 0xdead0001, // a nice, distinctive value

Expand Down
4 changes: 2 additions & 2 deletions GeneralsMD/Code/GameEngine/Include/Common/GameAudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class Object;
class SoundManager;


enum AudioAffect;
enum AudioType;
enum AudioAffect CPP_11(: int);
enum AudioType CPP_11(: int);

struct AudioEventInfo;
struct AudioRequest;
Expand Down
20 changes: 10 additions & 10 deletions GeneralsMD/Code/GameEngine/Include/Common/GameCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ enum
};

//-------------------------------------------------------------------------------------------------
enum GameDifficulty
enum GameDifficulty CPP_11(: int)
{
DIFFICULTY_EASY,
DIFFICULTY_NORMAL,
Expand All @@ -148,7 +148,7 @@ enum GameDifficulty
};

//-------------------------------------------------------------------------------------------------
enum PlayerType
enum PlayerType CPP_11(: int)
{
PLAYER_HUMAN, ///< player is human-controlled
PLAYER_COMPUTER, ///< player is computer-controlled
Expand All @@ -158,7 +158,7 @@ enum PlayerType

//-------------------------------------------------------------------------------------------------
/// A PartitionCell can be one of three states for Shroud
enum CellShroudStatus
enum CellShroudStatus CPP_11(: int)
{
CELLSHROUD_CLEAR,
CELLSHROUD_FOGGED,
Expand All @@ -169,7 +169,7 @@ enum CellShroudStatus

//-------------------------------------------------------------------------------------------------
/// Since an object can take up more than a single PartitionCell, this is a status that applies to the whole Object
enum ObjectShroudStatus
enum ObjectShroudStatus CPP_11(: int)
{
OBJECTSHROUD_INVALID, ///< indeterminate state, will recompute
OBJECTSHROUD_CLEAR, ///< object is not shrouded at all (ie, completely visible)
Expand All @@ -182,7 +182,7 @@ enum ObjectShroudStatus
};

//-------------------------------------------------------------------------------------------------
enum GuardMode
enum GuardMode CPP_11(: int)
{
GUARDMODE_NORMAL,
GUARDMODE_GUARD_WITHOUT_PURSUIT, // no pursuit out of guard area
Expand All @@ -203,7 +203,7 @@ enum

/// Veterancy level define needed by several files that don't need the full Experience code.
// NOTE NOTE NOTE: Keep TheVeterencyNames in sync with these.
enum VeterancyLevel
enum VeterancyLevel CPP_11(: int)
{
LEVEL_REGULAR = 0,
LEVEL_VETERAN,
Expand All @@ -222,7 +222,7 @@ extern const char *TheVeterancyNames[];

//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
enum CommandSourceType
enum CommandSourceType CPP_11(: int)
{

CMD_FROM_PLAYER = 0,
Expand All @@ -234,7 +234,7 @@ enum CommandSourceType
}; ///< the source of a command

//-------------------------------------------------------------------------------------------------
enum AbleToAttackType
enum AbleToAttackType CPP_11(: int)
{
_ATTACK_FORCED = 0x01,
_ATTACK_CONTINUED = 0x02,
Expand Down Expand Up @@ -472,7 +472,7 @@ class DLINK_ITERATOR

// ------------------------------------------------------------------------

enum WhichTurretType
enum WhichTurretType CPP_11(: int)
{
TURRET_INVALID = -1,

Expand All @@ -495,7 +495,7 @@ inline Real stdAngleDiff(Real a1, Real a2)

// ------------------------------------------------------------------------
// NOTE NOTE NOTE: Keep TheRelationShipNames in sync with this enum
enum Relationship
enum Relationship CPP_11(: int)
{
ENEMIES = 0,
NEUTRAL,
Expand Down
Loading