From 401901c4f722082608369f7fe3a7da9db08aa2a3 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Sun, 22 Dec 2024 16:46:42 +0100 Subject: [PATCH] Replace sizeof/sizeof by std::size --- Descent3/Briefing.cpp | 2 +- Descent3/CtlCfgElem.cpp | 2 +- Descent3/GameCheat.cpp | 2 +- Descent3/LoadLevel.cpp | 4 ++-- Descent3/Player.cpp | 4 ++-- Descent3/TelComCargo.cpp | 2 +- Descent3/ctlconfig.cpp | 4 ++-- Descent3/dedicated_server.cpp | 2 +- Descent3/fireball.cpp | 2 +- Descent3/localization.cpp | 2 +- Descent3/multisafe.cpp | 6 +++--- Descent3/newui_core.cpp | 2 +- Descent3/objinfo.cpp | 2 +- Descent3/weapon.cpp | 2 +- ddio/lnxmouse.cpp | 2 +- ddio/sdlcontroller.cpp | 4 ++-- editor/FilePageDialog.cpp | 2 +- editor/MainFrm.cpp | 2 +- editor/ObjectDialog.cpp | 2 +- editor/OrphanRemoveDlg.cpp | 2 +- grtext/grtext.cpp | 2 +- legacy/hogedit/MainFrm.cpp | 2 +- scripts/AIGame.cpp | 4 ++-- scripts/clutter.cpp | 2 +- 24 files changed, 31 insertions(+), 31 deletions(-) diff --git a/Descent3/Briefing.cpp b/Descent3/Briefing.cpp index 09c36bcb..fb147e87 100644 --- a/Descent3/Briefing.cpp +++ b/Descent3/Briefing.cpp @@ -231,7 +231,7 @@ static tBriefingTag HotTags[] = { {"#PLEVELNUM#", TAG_PLEVELNUM, -1}, {"#NLEVELNUM#", TAG_NLEVELNUM, -1}, }; -static const int NumHotTags = sizeof(HotTags) / sizeof(tBriefingTag); +static const int NumHotTags = std::size(HotTags); static int osb_xoff = 0, osb_yoff = 0; static int current_screen = -1; diff --git a/Descent3/CtlCfgElem.cpp b/Descent3/CtlCfgElem.cpp index a8ad16a9..4d4d5f99 100644 --- a/Descent3/CtlCfgElem.cpp +++ b/Descent3/CtlCfgElem.cpp @@ -392,7 +392,7 @@ static int16_t key_binding_indices[] = { KEY_PADPERIOD, KEY_PADENTER, KEY_RCTRL, KEY_PADDIVIDE, KEY_RALT, KEY_HOME, KEY_UP, KEY_PAGEUP, KEY_LEFT, KEY_RIGHT, KEY_END, KEY_DOWN, KEY_PAGEDOWN, KEY_INSERT, KEY_DELETE, 0xff}; -#define NUM_KEYBINDSTRINGS (sizeof(Ctltext_KeyBindings) / sizeof(Ctltext_KeyBindings[0])) +#define NUM_KEYBINDSTRINGS std::size(Ctltext_KeyBindings) #define F_ELEM_HILITE 0x1 #define F_ELEM_ACTIVE 0x2 diff --git a/Descent3/GameCheat.cpp b/Descent3/GameCheat.cpp index d6ff6365..5321da81 100644 --- a/Descent3/GameCheat.cpp +++ b/Descent3/GameCheat.cpp @@ -186,7 +186,7 @@ const char *LamerCheats[] = { "#/;=3J8F", // nosferatu "J#.DEJCT", // pandorasbox }; -#define N_LAMER_CHEATS (sizeof(LamerCheats) / sizeof(*LamerCheats)) +#define N_LAMER_CHEATS std::size(LamerCheats) /* Demo Cheat Codes diff --git a/Descent3/LoadLevel.cpp b/Descent3/LoadLevel.cpp index 4638a411..9fa8f4e0 100644 --- a/Descent3/LoadLevel.cpp +++ b/Descent3/LoadLevel.cpp @@ -1457,7 +1457,7 @@ tConvertObject object_convert[] = { {OBJ_POWERUP, -2, "ProxMinepowerup", CONV_MULTI}, {OBJ_POWERUP, -2, "energy", 0}}; -int object_convert_size = sizeof(object_convert) / sizeof(tConvertObject); +int object_convert_size = std::size(object_convert); uint32_t chunk_start, chunk_size, filelen; @@ -3591,7 +3591,7 @@ const char *New_door_names[] = {"MARK'S OLD DOOR", "PTMC Industrial 1", "PTMC Covert 1"}; -#define NUM_RENAMED_DOORS (sizeof(Old_door_names) / sizeof(*Old_door_names)) +#define NUM_RENAMED_DOORS std::size(Old_door_names) // Deals with some renamed doors. Translates the old name to the new name, then looks up the id int SpecialFindDoorName(const char *name) { diff --git a/Descent3/Player.cpp b/Descent3/Player.cpp index 7d54094d..58276cad 100644 --- a/Descent3/Player.cpp +++ b/Descent3/Player.cpp @@ -2864,7 +2864,7 @@ int PlayerSpewObject(object *parent, int type, int id, int timed, void *sinfo) { // This mapping should really be on the powerup page const char *powerup_multipacks[] = {"Concussion", "4packConc", "Frag", "4packFrag", "Guided", "4packGuided", "Homing", "4packHoming"}; -#define N_POWERUP_MULTIPACKS (sizeof(powerup_multipacks) / sizeof(*powerup_multipacks) / 2) +#define N_POWERUP_MULTIPACKS (std::size(powerup_multipacks) / 2) // Returns the index of the multipack version of the specified powerup, or -1 if none int FindMultipackPowerup(int single_index) { @@ -3231,7 +3231,7 @@ static vector Death_cam_vectors[] = {{0, 1, 0}, {0, 1, -1}, {0, 0, -1}, {0, -1, {0, 0, 1}, {0, 1, 1}, {1, 0, 0}, {1, 0, -1}, {-1, 0, -1}, {-1, 0, 0}, {-1, 0, 1}, {1, 0, 1}, {1, 1, 0}, {1, -1, 0}, {-1, -1, 0}, {-1, 1, 0}}; -#define NUM_DEATH_VECS (sizeof(Death_cam_vectors) / sizeof(vector)) +#define NUM_DEATH_VECS std::size(Death_cam_vectors) float MoveDeathCam(int slot, vector *vec, float distance) { fvi_info hit_data; diff --git a/Descent3/TelComCargo.cpp b/Descent3/TelComCargo.cpp index 579d5800..6c800bff 100644 --- a/Descent3/TelComCargo.cpp +++ b/Descent3/TelComCargo.cpp @@ -131,7 +131,7 @@ tLineInfo StatusLines[] = { {LIT_TITLE, "Secondaries", LID_SECONDARIES}, {LIT_TITLE, "Counter Measures", LID_COUNTERMEASURES}, {LIT_TITLE, "Inventory", LID_INVENTORY}}; -#define NUM_LINES (sizeof(StatusLines) / sizeof(tLineInfo)) +#define NUM_LINES std::size(StatusLines) #define TITLE_X 30 + TCminx #define VALUE_X 400 + TCminx static int TCminx, TCmaxx, TCminy, TCmaxy; diff --git a/Descent3/ctlconfig.cpp b/Descent3/ctlconfig.cpp index 88bdb1df..2e230c33 100644 --- a/Descent3/ctlconfig.cpp +++ b/Descent3/ctlconfig.cpp @@ -406,8 +406,8 @@ t_cfg_element Cfg_joy_elements[] = {{-1, CtlText_WeaponGroup, CCITEM_WPN_X2, CCI {ctfTOGGLE_BANKBUTTON, CtlText_ToggleBank, 0, 0}, {ctfBANK_LEFTBUTTON, CtlText_BankLeft, 0, 0}, {ctfBANK_RIGHTBUTTON, CtlText_BankRight, 0, 0}}; -#define N_JOY_CFG_FN (sizeof(Cfg_joy_elements) / sizeof(t_cfg_element)) -#define N_KEY_CFG_FN (sizeof(Cfg_key_elements) / sizeof(t_cfg_element)) +#define N_JOY_CFG_FN std::size(Cfg_joy_elements) +#define N_KEY_CFG_FN std::size(Cfg_key_elements) static void ctl_cfg_set_and_verify_changes(int16_t fnid, ct_type elem_type, uint8_t controller, uint8_t elem, int8_t slot); static void ctl_cfg_element_options_dialog(int16_t fnid); // used for adjusting settings. diff --git a/Descent3/dedicated_server.cpp b/Descent3/dedicated_server.cpp index b6acec18..15e11b8f 100644 --- a/Descent3/dedicated_server.cpp +++ b/Descent3/dedicated_server.cpp @@ -226,7 +226,7 @@ static cvar_entry CVars[] = { #define CVAR_SETDIFF 34 #define CVAR_MOTD 35 -#define MAX_CVARS (sizeof(CVars) / sizeof(cvar_entry)) +#define MAX_CVARS std::size(CVars) // Takes the data that the config file has an runs a server based on that data // Returns true if ok, false if something is wrong diff --git a/Descent3/fireball.cpp b/Descent3/fireball.cpp index 3c16fe54..2ba31aba 100644 --- a/Descent3/fireball.cpp +++ b/Descent3/fireball.cpp @@ -1319,7 +1319,7 @@ const char *dead_object_types[] = { "swatter", "swatter(deadmodel)", "Hangturret", "Securityturret(DEAD)", "Lance", "Lance(DEAD)", "L10 swatter", "swatter(deadmodel)", }; -#define N_DEAD_OBJECT_TYPES (sizeof(dead_object_types) / sizeof(*dead_object_types) / 2) +#define N_DEAD_OBJECT_TYPES (std::size(dead_object_types) / 2) #include "osiris_predefs.h" // Creates a dead version of the given object void CreateDeadObject(object *objp) { diff --git a/Descent3/localization.cpp b/Descent3/localization.cpp index 1ef04654..68df3d9d 100644 --- a/Descent3/localization.cpp +++ b/Descent3/localization.cpp @@ -110,7 +110,7 @@ tLangTag Language_tags[] = { {"!I!", -1}, // Italian {"!F!", -1}, // French }; -int Num_languages = sizeof(Language_tags) / sizeof(tLangTag); +int Num_languages = std::size(Language_tags); // The following data, in the anonymous namespace, are static to this file namespace { diff --git a/Descent3/multisafe.cpp b/Descent3/multisafe.cpp index 4f3a9e5e..84acbac2 100644 --- a/Descent3/multisafe.cpp +++ b/Descent3/multisafe.cpp @@ -2513,7 +2513,7 @@ struct { {"Fusioncannon", FUSION_INDEX, TXI_MSG_FUSION, TXI_MSG_FUSIONHAVE, -1, -1}, {"Omegacannon", OMEGA_INDEX, TXI_MSG_OMEGA, TXI_MSG_OMEGAHAVE, -1, -1}, }; -#define NUM_POWERUP_TYPES_PRIMARY (sizeof(powerup_data_primary) / sizeof(*powerup_data_primary)) +#define NUM_POWERUP_TYPES_PRIMARY std::size(powerup_data_primary) struct { const char *name; int weapon_index; @@ -2534,7 +2534,7 @@ struct { {"4PackFrag", FRAG_INDEX, TXI_MSG_FRAG, TXI_MSG_MULTI_FRAG, TXI_MSG_FRAGFULL}, {"4PackGuided", GUIDED_INDEX, TXI_MSG_GUIDED, TXI_MSG_MULTI_GUIDED, TXI_MSG_GUIDEDFULL}, }; -#define NUM_POWERUP_TYPES_SECONDARY (sizeof(powerup_data_secondary) / sizeof(*powerup_data_secondary)) +#define NUM_POWERUP_TYPES_SECONDARY std::size(powerup_data_secondary) struct { const char *name; int weapon_index; @@ -2542,7 +2542,7 @@ struct { } powerup_data_ammo[] = {{"Vauss clip", VAUSS_INDEX, TXI_MSG_VAUSSAMMO, TXI_MSG_VAUSSFULL}, {"MassDriverAmmo", MASSDRIVER_INDEX, TXI_MSG_MASSAMMO, TXI_MSG_MASSFULL}, {"NapalmTank", NAPALM_INDEX, TXI_MSG_NAPALMFUEL, TXI_MSG_NAPALMFULL}}; -#define NUM_POWERUP_TYPES_AMMO (sizeof(powerup_data_ammo) / sizeof(*powerup_data_ammo)) +#define NUM_POWERUP_TYPES_AMMO std::size(powerup_data_ammo) void ShowAmmoAddedMessage(int weapon_index, int msg_index, int added) { int added_frac = 0; if (Ships[Players[Player_num].ship_index].fire_flags[weapon_index] & SFF_TENTHS) { diff --git a/Descent3/newui_core.cpp b/Descent3/newui_core.cpp index 7da027c6..fbfc62cd 100644 --- a/Descent3/newui_core.cpp +++ b/Descent3/newui_core.cpp @@ -529,7 +529,7 @@ static const char *Preloaded_bitmap_list[] = { NEWUI_WIN_TITLE_L_FILE, NEWUI_WIN_TITLE_C_FILE, NEWUI_WIN_TITLE_R_FILE, }; -#define N_UI_PRELOADED_BITMAPS (sizeof(Preloaded_bitmap_list) / sizeof(const char *)) +#define N_UI_PRELOADED_BITMAPS std::size(Preloaded_bitmap_list) int UI_frame_result = -1; static newuiResources Newui_resources; diff --git a/Descent3/objinfo.cpp b/Descent3/objinfo.cpp index 3af2fd9f..a833379d 100644 --- a/Descent3/objinfo.cpp +++ b/Descent3/objinfo.cpp @@ -52,7 +52,7 @@ int Num_object_ids[MAX_OBJECT_TYPES]; const char *Static_object_names[] = {TBL_GENERIC("GuideBot"), TBL_GENERIC("ChaffChunk"),TBL_GENERIC("GuideBotRed")}; // #endif -#define NUM_STATIC_OBJECTS (sizeof(Static_object_names) / sizeof(*Static_object_names)) +#define NUM_STATIC_OBJECTS std::size(Static_object_names) #ifdef EDITOR const char * const Movement_class_names[] = {"Standing", "Flying", "Rolling", "Walking", "Jumping"}; diff --git a/Descent3/weapon.cpp b/Descent3/weapon.cpp index 91044a6c..7ddc5d62 100644 --- a/Descent3/weapon.cpp +++ b/Descent3/weapon.cpp @@ -714,7 +714,7 @@ int MoveWeaponFromIndex(int index) { // This is a very confusing function. It takes all the weapons that we have loaded // and remaps then into their proper places (if they are static). void RemapWeapons() { - int limit = sizeof(Static_weapon_names) / sizeof(void *); + int limit = std::size(Static_weapon_names); int i; for (i = 0; i < MAX_STATIC_WEAPONS; i++) { diff --git a/ddio/lnxmouse.cpp b/ddio/lnxmouse.cpp index 12f41152..ad0253c6 100644 --- a/ddio/lnxmouse.cpp +++ b/ddio/lnxmouse.cpp @@ -537,7 +537,7 @@ const char *ddio_MouseGetBtnText(int btn) { } const char *ddio_MouseGetAxisText(int axis) { - if (axis >= static_cast(sizeof(Ctltext_MseAxisBindings) / sizeof(Ctltext_MseAxisBindings[0])) || axis < 0) + if (axis < 0 || static_cast(axis) >= std::size(Ctltext_MseAxisBindings)) return (""); return Ctltext_MseAxisBindings[axis]; } diff --git a/ddio/sdlcontroller.cpp b/ddio/sdlcontroller.cpp index 6c5c3728..93787d48 100644 --- a/ddio/sdlcontroller.cpp +++ b/ddio/sdlcontroller.cpp @@ -157,8 +157,8 @@ static char Ctltext_BtnBindings[][16] = { char Ctltext_PovBindings[][16] = {"", "pov-U", "pov-R", "pov-D", "pov-L"}; -#define NUM_AXISBINDSTRINGS (sizeof(Ctltext_AxisBindings) / sizeof(Ctltext_AxisBindings[0])) -#define NUM_BTNBINDSTRINGS (sizeof(Ctltext_BtnBindings) / sizeof(Ctltext_AxisBindings[0])) +#define NUM_AXISBINDSTRINGS std::size(Ctltext_AxisBindings) +#define NUM_BTNBINDSTRINGS std::size(Ctltext_BtnBindings) // retrieves binding text for desired function, binding, etc. const char *sdlgameController::get_binding_text(ct_type type, uint8_t ctrl, uint8_t bind) { diff --git a/editor/FilePageDialog.cpp b/editor/FilePageDialog.cpp index 8f538c11..071252ce 100644 --- a/editor/FilePageDialog.cpp +++ b/editor/FilePageDialog.cpp @@ -39,7 +39,7 @@ static char THIS_FILE[] = __FILE__; char *DirectoryNames[] = {"Graphics", "Rooms", "Sounds", "Models", "Levels", "Briefings", "Misc", "Art", "Scripts", "Music", "Voice"}; -int NumDirectoryNames = sizeof(DirectoryNames) / sizeof(char *); +int NumDirectoryNames = std::size(DirectoryNames); ///////////////////////////////////////////////////////////////////////////// // CFilePageDialog dialog diff --git a/editor/MainFrm.cpp b/editor/MainFrm.cpp index f1c5c62a..d22969de 100644 --- a/editor/MainFrm.cpp +++ b/editor/MainFrm.cpp @@ -1044,7 +1044,7 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { return -1; // fail to create } - if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators) / sizeof(UINT))) { + if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, std::size(indicators))) { TRACE0("Failed to create status bar\n"); return -1; // fail to create } diff --git a/editor/ObjectDialog.cpp b/editor/ObjectDialog.cpp index de6024b5..94f1e97a 100644 --- a/editor/ObjectDialog.cpp +++ b/editor/ObjectDialog.cpp @@ -269,7 +269,7 @@ bool f_allow_objects_to_be_pushed_through_walls = false; void DrawItemModel(grHardwareSurface *surf, int model_num); -#define NUM_EDIT_OBJTYPES (sizeof(edit_object_types) / sizeof(*edit_object_types)) +#define NUM_EDIT_OBJTYPES std::size(edit_object_types) ///////////////////////////////////////////////////////////////////////////// // CObjectDialog dialog diff --git a/editor/OrphanRemoveDlg.cpp b/editor/OrphanRemoveDlg.cpp index fd25da70..32a93951 100644 --- a/editor/OrphanRemoveDlg.cpp +++ b/editor/OrphanRemoveDlg.cpp @@ -357,7 +357,7 @@ const char *orphan_ignore[] = { "anarchy.str", "coop.str", "ctf.str", "entropy.str", "dmfc.str", "d3.str", "hoard.str", "dp_modem.str", "dp_serial.str", "hyper.str", "ipxclient.str", "lanclient.str", "monster.str", "mtclient.str", "tanarchy.str"}; -int num_orphan_ignore = sizeof(orphan_ignore) / sizeof(char *); +int num_orphan_ignore = std::size(orphan_ignore); bool IsFileUsed(const char *filename) { bool found = false; diff --git a/grtext/grtext.cpp b/grtext/grtext.cpp index af90f252..8aaaa165 100644 --- a/grtext/grtext.cpp +++ b/grtext/grtext.cpp @@ -208,7 +208,7 @@ static badword bad_words[] = { {0xbd, 0xa4, 0xbe, 0xbe, 0x00} // piss }; -#define NUM_BAD_WORDS (sizeof(bad_words) / sizeof(badword)) +#define NUM_BAD_WORDS std::size(bad_words) static const char subst_chars[] = "#!&@&#%*"; diff --git a/legacy/hogedit/MainFrm.cpp b/legacy/hogedit/MainFrm.cpp index 3b50fd94..d51611e1 100644 --- a/legacy/hogedit/MainFrm.cpp +++ b/legacy/hogedit/MainFrm.cpp @@ -94,7 +94,7 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { return -1; // fail to create } - if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators) / sizeof(UINT))) { + if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, std::size(indicators))) { TRACE0("Failed to create status bar\n"); return -1; // fail to create } diff --git a/scripts/AIGame.cpp b/scripts/AIGame.cpp index b329a80d..9bc54d58 100644 --- a/scripts/AIGame.cpp +++ b/scripts/AIGame.cpp @@ -1629,7 +1629,7 @@ static tThiefItems ThiefableItems[] = { {6, THIEFABLEITEM_ACCESSORY, 1.00f, 0.60f, 1.00f, TXT_WEAP_RAPIDFIRE}, // RapidFire {7, THIEFABLEITEM_ACCESSORY, 1.00f, 0.60f, 1.00f, TXT_WEAP_QUADLASERS}, // Quads }; -static int numThiefableItems = sizeof(ThiefableItems) / sizeof(tThiefItems); +static int numThiefableItems = std::size(ThiefableItems); struct inv_item { uint16_t id; @@ -1728,7 +1728,7 @@ static tSuperThiefItems SuperThiefableItems[] = { {19, -1, THIEFABLEITEM_SECONDARY, .2f, TXT_WEAP_BLACKSHARK, "", ""}, // Black Shark }; -static int numSuperThiefableItems = sizeof(SuperThiefableItems) / sizeof(tSuperThiefItems); +static int numSuperThiefableItems = std::size(SuperThiefableItems); #define SUPERTHIEF_MELEE_DIST 50.0f diff --git a/scripts/clutter.cpp b/scripts/clutter.cpp index d74c5a6a..92a02a5d 100644 --- a/scripts/clutter.cpp +++ b/scripts/clutter.cpp @@ -75,7 +75,7 @@ static tScriptInfo ScriptIDs[] = {{ID_FRAGCRATE, "fragcrate"}, {ID_FALLINGROCK, "FallingRock"}, {ID_LAVAROCK, "LavaRock"}}; -static int NumScriptIDs = sizeof(ScriptIDs) / sizeof(tScriptInfo); +static int NumScriptIDs = std::size(ScriptIDs); class ClutterScript { public: