Definition of base types and functions in a cross-platform compatible way. More...
#include <stdint.h>
#include <cstdio>
#include <cstddef>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <cassert>
Go to the source code of this file.
Defines | |
#define | __STDC_LIMIT_MACROS |
#define | UINT64_MAX (18446744073709551615ULL) |
#define | INT64_MAX (9223372036854775807LL) |
#define | INT64_MIN (-INT64_MAX - 1) |
#define | UINT32_MAX (4294967295U) |
#define | INT32_MAX (2147483647) |
#define | INT32_MIN (-INT32_MAX - 1) |
#define | UINT16_MAX (65535U) |
#define | INT16_MAX (32767) |
#define | INT16_MIN (-INT16_MAX - 1) |
#define | UINT8_MAX (255) |
#define | INT8_MAX (127) |
#define | INT8_MIN (-INT8_MAX - 1) |
#define | SIZE_MAX ((size_t)-1) |
#define | fopen(file, mode) fopen(OTTD2FS(file), mode) |
#define | SQ2OTTD(name) (name) |
#define | OTTD2SQ(name) (name) |
#define | PATHSEP "/" |
#define | PATHSEPCHAR '/' |
#define | OTTD_PRINTF64 "%lld" |
#define | OTTD_PRINTFHEX64 "%llx" |
#define | PRINTF_SIZE "%zu" |
#define | PERSONAL_DIR "" |
#define | assert_compile(expr) typedef int __ct_assert__[1 - 2 * !(expr)] |
#define | assert_tcompile(expr) assert(expr) |
#define | M_PI_2 1.57079632679489661923 |
#define | M_PI 3.14159265358979323846 |
#define | lengthof(x) (sizeof(x) / sizeof(x[0])) |
Return the length of an fixed size array. | |
#define | endof(x) (&x[lengthof(x)]) |
Get the end element of an fixed size array. | |
#define | lastof(x) (&x[lengthof(x) - 1]) |
Get the last element of an fixed size array. | |
#define | cpp_offsetof(s, m) (((size_t)&reinterpret_cast<const volatile char&>((((s*)(char*)8)->m))) - 8) |
#define | offsetof(s, m) cpp_offsetof(s, m) |
#define | cpp_sizeof(base, variable) (sizeof(((base*)8)->variable)) |
Gets the size of a variable within a class. | |
#define | cpp_lengthof(base, variable) (cpp_sizeof(base, variable) / cpp_sizeof(base, variable[0])) |
Gets the length of an array variable within a class. | |
#define | NOT_REACHED() error("NOT_REACHED triggered at line %i of %s", __LINE__, __FILE__) |
#define | assert(expression) if (!(expression)) error("Assertion failed at line %i of %s: %s", __LINE__, __FILE__, #expression); |
#define | OTTD_ASSERT |
#define | MAX_PATH 260 |
#define | MAX_UVALUE(type) ((type)~(type)0) |
The largest value that can be entered in a variable. | |
Typedefs | |
typedef unsigned char | byte |
typedef unsigned int | uint |
typedef unsigned char | uint8 |
typedef signed char | int8 |
typedef unsigned short | uint16 |
typedef signed short | int16 |
typedef unsigned int | uint32 |
typedef signed int | int32 |
typedef unsigned __int64 | uint64 |
typedef signed __int64 | int64 |
Functions | |
const char * | FS2OTTD (const char *name) |
const char * | OTTD2FS (const char *name) |
assert_compile (sizeof(uint64)==8) | |
assert_compile (sizeof(uint32)==4) | |
assert_compile (sizeof(uint16)==2) | |
assert_compile (sizeof(uint8)==1) | |
assert_compile (SIZE_MAX >=UINT32_MAX) | |
void NORETURN CDECL | usererror (const char *str,...) WARN_FORMAT(1 |
void NORETURN CDECL void NORETURN CDECL | error (const char *str,...) WARN_FORMAT(1 |
static void | free (const void *ptr) |
Version of the standard free that accepts const pointers. |
Definition of base types and functions in a cross-platform compatible way.
Definition in file stdafx.h.
#define cpp_lengthof | ( | base, | ||
variable | ||||
) | (cpp_sizeof(base, variable) / cpp_sizeof(base, variable[0])) |
Gets the length of an array variable within a class.
base | The class the variable is in. | |
variable | The array variable to get the size of. |
Definition at line 432 of file stdafx.h.
Referenced by NIHTown::GetPSASize(), and NIHIndustry::GetPSASize().
#define cpp_sizeof | ( | base, | ||
variable | ||||
) | (sizeof(((base*)8)->variable)) |
#define endof | ( | x | ) | (&x[lengthof(x)]) |
Get the end element of an fixed size array.
x | The pointer to the first element of the array |
Definition at line 403 of file stdafx.h.
Referenced by DoLoad(), DumpDebugFacilityNames(), SmallStackSafeStackAlloc< T, length >::EndOf(), GetDebugString(), AirportSpec::GetIndex(), GetSavegameFormat(), GrowTown(), HandleCrash(), CrashLog::InitialiseCrashLog(), LoadFromHighScore(), SaveToHighScore(), SetDebugString(), TerraformTileHeight(), and SelectCompanyLiveryWindow::UpdateWidgetSize().
#define lastof | ( | x | ) | (&x[lengthof(x) - 1]) |
Get the last element of an fixed size array.
x | The pointer to the first element of the array |
Definition at line 411 of file stdafx.h.
Referenced by ScenarioScanner::AddFile(), FiosFileScanner::AddFile(), TarScanner::AddFile(), StringFilter::AddLine(), Subsidy::AwardTo(), CargoSpecNameSorter(), NetworkChatWindow::ChatTabCompletionNextItem(), CheckExternalFiles(), CloneVehicleName(), CmdFoundTown(), CopyFromOldName(), CopyOutDParam(), debug_print(), CrashLogOSX::DisplayCrashDialog(), DoAutosave(), ClientNetworkContentSocketHandler::DownloadSelectedContentHTTP(), NetworkContentListWindow::DrawDetails(), DrawNewsString(), DrawRoadVehDetails(), DrawString(), DrawStringMultiLine(), CheatWindow::DrawWidget(), AIInfo::DummyConstructor(), EngineNameSorter(), ErrorUnknownCallbackResult(), ExtractTar(), FioFOpenFile(), FiosGetFileList(), FiosMakeHeightmapName(), FormatString(), GamelogRevision(), GenerateCompanyName(), GeneratePresidentName(), NetworkAddress::GetAddressAsString(), GetAllCargoSuffixes(), GetDebugString(), GetFileTitle(), GetFiosItem(), GetFullFilename(), GetKeyboardLayout(), GetLanguageList(), GetSavegameFormat(), GetSaveLoadErrorString(), GetStringBoundingBox(), GetStringHeight(), GetStringLineCount(), GetTextfile(), VehicleGroupWindow::GroupNameSorter(), FileStringReader::HandlePragma(), HandleSavegameLoadCrash(), HelpDialogFunc(), IndustryDirectoryWindow::IndustryNameSorter(), IndustryTypeNameSorter(), IniSaveSettings(), InitializeMusic(), IsGoodGRFConfigList(), IsSameScript(), LanguagePackHeader::IsValid(), KeycodeToString(), ScriptInstance::LoadCompatibilityScripts(), LoadFromHighScore(), LoadTranslations(), CrashLogOSX::MakeCrashLog(), CrashLog::MakeCrashLog(), MakePNGImage(), MakeScreenshot(), MakeScreenshotName(), MidiSendCommand(), DropDownListStringItem::NatSortFunc(), NetworkAddChatMessage(), NetworkAddress::NetworkAddress(), NetworkFindBroadcastIPsInternal(), NetworkGameListHandleDelayedInsert(), NetworkHandlePauseChange(), NetworkSendCommand(), NetworkServerChangeClientName(), NetworkServerSendChat(), NetworkServerSetCompanyPassword(), NetworkUDPQueryServer(), NetworkUpdateClientName(), SaveLoadWindow::OnClick(), BaseNetworkContentDownloadStatusWindow::OnDownloadProgress(), NetworkStartServerWindow::OnEditboxChanged(), NetworkGameWindow::OnEditboxChanged(), AIDebugWindow::OnEditboxChanged(), LandInfoWindow::OnInit(), CustomCurrencyWindow::OnQueryTextFinished(), NetworkStartServerWindow::OnQueryTextFinished(), ClientNetworkContentSocketHandler::OnReceiveData(), DepotWindow::OnRightClick(), NetworkContentListWindow::OpenExternalSearch(), StringReader::ParseFile(), MusicDriver_Win32::PlaySong(), MusicDriver_ExtMidi::PlaySong(), PrintGrfInfo(), ReadLanguagePack(), ServerNetworkUDPSocketHandler::Receive_CLIENT_FIND_SERVER(), ServerNetworkUDPSocketHandler::Receive_CLIENT_GET_NEWGRFS(), ClientNetworkGameSocketHandler::Receive_SERVER_CHAT(), ClientNetworkGameSocketHandler::Receive_SERVER_CHECK_NEWGRFS(), ClientNetworkGameSocketHandler::Receive_SERVER_CLIENT_INFO(), ClientNetworkUDPSocketHandler::Receive_SERVER_RESPONSE(), DriverFactoryBase::RegisterDriver(), NetworkAddress::Resolve(), SaveHighScoreValue(), SaveHighScoreValueNetwork(), SaveKeycodes(), IniFile::SaveToDisk(), FileScanner::Scan(), Script_CreateDummy(), Script_CreateDummyInfo(), DriverFactoryBase::SelectDriver(), ServerNetworkGameSocketHandler::SendCompanyInfo(), ServerNetworkAdminSocketHandler::SendCompanyInfo(), ServerNetworkAdminSocketHandler::SendCompanyUpdate(), ServerNetworkGameSocketHandler::SendError(), ServerNetworkAdminSocketHandler::SendError(), SetFallbackFont(), TextfileWindow::SetFontNames(), LanguagePackGlyphSearcher::SetFontNames(), SetScreenshotFormat(), ShowErrorMessage(), ShowHelp(), ShowNewGrfVehicleError(), SignList::SignNameFilter(), SignList::SignNameSorter(), CompanyStationsWindow::StationNameSorter(), str_fmt(), TownDirectoryWindow::TownNameSorter(), TranslateGRFStrings(), NetworkContentListWindow::TypeSorter(), ScanProgressWindow::UpdateNewGRFScanStatus(), ViewportSign::UpdatePosition(), VehicleNameSorter(), VerifyTownName(), and DriverFactoryBase::~DriverFactoryBase().
#define lengthof | ( | x | ) | (sizeof(x) / sizeof(x[0])) |
Return the length of an fixed size array.
Unlike sizeof this function returns the number of elements of the given type.
x | The pointer to the first element of the array |
Definition at line 395 of file stdafx.h.
Referenced by _GenerateWorld(), AddGenericCallback(), AddGRFString(), AddNewsItem(), AfterLoadGame(), NWidgetServerListHeader::AssignSizePosition(), CalcHeightdiff(), CanCargoServiceIndustry(), ChangeGRFNumUsedParams(), ChangeGRFParamMask(), ChangeIndustryProduction(), NetworkChatWindow::ChatTabCompletion(), CheckForMissingSprites(), AyStar::CheckTile(), CmdChangeCompanySetting(), CmdDoTownAction(), CmdFoundTown(), CmdRenamePresident(), CMSAMine(), Squirrel::CompileError(), IndustryCargoesWindow::ComputeCargoDisplay(), VehicleGroupWindow::ComputeGroupInfoSize(), IndustryCargoesWindow::ComputeIndustryDisplay(), CargoesRow::ConnectIndustryAccepted(), CargoesRow::ConnectIndustryProduced(), ScriptInfo::Constructor(), CopyFile(), ErrorMessageData::CopyOutDParams(), IndustryCargoesWindow::CountMatchingAcceptingIndustries(), IndustryCargoesWindow::CountMatchingProducingIndustries(), debug(), debug_print(), DeliverGoodsToIndustry(), DeterminePaths(), DoCommandPInternal(), DoCreateNewIndustry(), DoLoad(), DoScanWorkingDirectory(), IndustryViewWindow::DrawInfo(), DrawNewsString(), NewsWindow::DrawWidget(), AboutWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), CompanyWindow::DrawWidget(), CheatWindow::DrawWidget(), error(), ErrorMessageData::ErrorMessageData(), Squirrel::ErrorPrintFunc(), ExtractTar(), FillNewGRFVehicleCache(), FindIndustryToDeliver(), FioCloseAll(), FiosDelete(), FiosGetFileList(), FixTTOEngines(), FormatBytes(), FormatString(), FreeTerminal(), FS2OTTD(), GenerateCompanyPasswordHash(), GenerateTownNameString(), AirportTileSpec::Get(), AirportSpec::Get(), CargoSpec::Get(), GetAllCargoSuffixes(), CargoSpec::GetArraySize(), GetBridgeSpec(), NWidgetScenarioToolbarContainer::GetButtonArrangement(), NWidgetMainToolbarContainer::GetButtonArrangement(), IndustryDirectoryWindow::GetCargoTransportedPercentsIfValid(), CargoArray::GetCount(), GetCurrentLocale(), GetDistanceFromNearbyHouse(), GetFullFilename(), GetGenericCallbackResult(), GetGRFContainerVersion(), IndustryDirectoryWindow::GetIndustryString(), GetMaskOfTownActions(), BuildTreesWindow::GetMaxTreeSpriteSize(), GetNetworkErrorMsg(), GetNewgrfCurrencyIdConverted(), GetNumberOfIndustries(), GRFFile::GetParam(), GetProductionAroundTiles(), CargoArray::GetSum(), GetTextfile(), GetVehicleSpriteGroup(), AirportSpec::GetWithoutOverride(), GRFConfig::GRFConfig(), GRFLoadConfig(), HandleIMEComposition(), StringReader::HandlePragma(), HelpDialogFunc(), IndustryCargoesWindow::HousesCanAccept(), IConsoleAliasExec(), IConsoleCmdExec(), IConsoleListSettings(), IndustryDirectoryWindow::IndustryProductionSorter(), InitializeLanguagePacks(), InitializeScreenshotFormats(), SpriteFontCache::InitializeUnicodeGlyphMap(), Textbuf::InsertClipboard(), IsCommandAllowedWhilePaused(), SmallSet< Tdir, items >::IsFull(), IsTileForestIndustry(), IsValidCommand(), NWidgetServerListHeader::IsWidgetVisible(), KeycodeToString(), LoadIntList(), LoadNewGRF(), LoadOldVehicle(), CrashLogWindows::LogModules(), CrashLogUnix::LogStacktrace(), MakeAustrianTownName(), CargoesRow::MakeCargoLabel(), MakeCatalanTownName(), MakeCzechTownName(), MakeDanishTownName(), MakeDutchTownName(), MakeEnglishAdditionalTownName(), MakeEnglishOriginalTownName(), MakeFinnishTownName(), MakeFrenchTownName(), MakeGermanTownName(), MakeHeightmapScreenshot(), MakeHungarianTownName(), MakeItalianTownName(), MakeNorwegianTownName(), MakePerformanceDetailPanels(), MakePolishTownName(), MakeRomanianTownName(), MakeScreenshotName(), MakeSillyTownName(), MakeSlovakTownName(), MakeSpanishTownName(), MakeSwedishTownName(), MakeSwissTownName(), MakeTurkishTownName(), VideoDriver_Win32::MakeWindow(), NewGRFWindow::NameSorter(), NetworkAddChatMessage(), NetworkChatWindow::NetworkChatWindow(), NetworkServerShowStatusToConsole(), NewGRFDisplay(), OrdersWindow::OnClick(), NetworkStartServerWindow::OnClick(), IndustryViewWindow::OnClick(), CheatWindow::OnClick(), SmallMapWindow::OnInit(), LandInfoWindow::OnInit(), MainWindow::OnPaint(), HighScoreWindow::OnPaint(), CompanyWindow::OnPaint(), AboutWindow::OnTick(), OTTD2FS(), ParseCode(), Squirrel::PrintFunc(), NetworkHTTPSocketHandler::Receive(), ClientNetworkGameSocketHandler::Receive_SERVER_ERROR(), NetworkGameSocketHandler::ReceiveCommand(), RemapTTOColour(), ResetGenericCallbacks(), ResetObjects(), Squirrel::RunError(), SaveHighScoreValue(), SaveHighScoreValueNetwork(), SaveVersionInConfig(), FileScanner::Scan(), ScanPath(), DriverFactoryBase::SelectDriver(), NetworkGameSocketHandler::SendCommand(), ServerNetworkAdminSocketHandler::SendCompanyEconomy(), ServerNetworkAdminSocketHandler::SendCompanyUpdate(), GRFConfig::SetParameterDefaults(), QueryWindow::SetStringParameters(), SetupCargoForClimate(), NWidgetScenarioToolbarContainer::SetupSmallestSize(), SmallMapWindow::SetZoomLevel(), ShowInfoF(), ShowMissingContentWindow(), ShowNewGRFError(), SlCalcConvFileLen(), SlCalcConvMemLen(), MusicDriver_Win32::Start(), StateGameLoop(), StringToContentType(), strnatcmp(), TriggerIndustryProduction(), UpdateIndustryStatistics(), UpdateStationAcceptance(), VehicleDetailsWindow::UpdateWidgetSize(), GameSettingsWindow::UpdateWidgetSize(), OrdersWindow::UpdateWidgetSize(), BuildObjectWindow::UpdateWidgetSize(), NewsWindow::UpdateWidgetSize(), NewGRFParametersWindow::UpdateWidgetSize(), AboutWindow::UpdateWidgetSize(), BuildIndustryWindow::UpdateWidgetSize(), CompanyLeagueWindow::UpdateWidgetSize(), CompanyWindow::UpdateWidgetSize(), CheatWindow::UpdateWidgetSize(), usererror(), CommandCost::UseTextRefStack(), and ErrorMessageData::~ErrorMessageData().
#define MAX_UVALUE | ( | type | ) | ((type)~(type)0) |
The largest value that can be entered in a variable.
type | the type of the variable |
Definition at line 491 of file stdafx.h.
Referenced by CompanyCheckBankrupt(), AirportTileSpec::Get(), Town::GetRandom(), Industry::GetRandom(), HandleBankruptcyTakeover(), Scrollbar::SetCapacity(), Scrollbar::SetCount(), and IConsoleLine::Truncate().