{"id":19691169,"url":"https://github.com/rdipardo/libmoreinttypes","last_synced_at":"2025-04-29T08:36:06.658Z","repository":{"id":45953793,"uuid":"301664738","full_name":"rdipardo/libmoreinttypes","owner":"rdipardo","description":"A minimal library of enhanced integer types for C","archived":false,"fork":false,"pushed_at":"2024-04-21T07:57:15.000Z","size":182,"stargazers_count":5,"open_issues_count":0,"forks_count":3,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-04-22T03:57:25.366Z","etag":null,"topics":["c","data-types-and-structures"],"latest_commit_sha":null,"homepage":"https://rdipardo.github.io/libmoreinttypes","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rdipardo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2020-10-06T08:41:08.000Z","updated_at":"2024-04-21T07:57:18.000Z","dependencies_parsed_at":"2024-04-07T02:50:06.915Z","dependency_job_id":null,"html_url":"https://github.com/rdipardo/libmoreinttypes","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rdipardo%2Flibmoreinttypes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rdipardo%2Flibmoreinttypes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rdipardo%2Flibmoreinttypes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rdipardo%2Flibmoreinttypes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rdipardo","download_url":"https://codeload.github.com/rdipardo/libmoreinttypes/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224160399,"owners_count":17265942,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","data-types-and-structures"],"created_at":"2024-11-11T19:08:15.640Z","updated_at":"2024-11-11T19:08:16.156Z","avatar_url":"https://github.com/rdipardo.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"Description\n===========\nA minimal library of enhanced integer types for C\n\nFeatures\n--------\n- read and write to encapsulated signed/unsigned `const` integers\n- parse numeric strings with free functions or by calling through \"member\" functions\n- [polymorphic function macros][]\n- use only what you need:\n\n\u003ctable border=\"0\"\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003ccode\u003e#include \u0026lt;moreinttypes/core.h\u0026gt;\u003c/code\u003e\u003c/td\u003e\n    \u003ctd align=\"right\"\u003e\u003cem\u003edata types\u003csup\u003e*\u003c/sup\u003e, math and string library\u003c/em\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003ccode\u003e#include \u0026lt;moreinttypes/utils.h\u0026gt;\u003c/code\u003e\u003c/td\u003e\n    \u003ctd align=\"right\"\u003e\u003cem\u003emath and string library only\u003c/em\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd colspan=\"2\"\u003e\n      \u003csmall\u003e\u003csup\u003e*\u003c/sup\u003e Since version 1.5, the following types are provided:\u003c/small\u003e\n      \u003cul style=\"list-style-type:none\"\u003e\n        \u003cli\u003eByte\u003c/li\u003e\n        \u003cli\u003eInt16\u003c/li\u003e\n        \u003cli\u003eInt32\u003c/li\u003e\n        \u003cli\u003eInt64\u003c/li\u003e\n        \u003cli\u003eSbyte\u003c/li\u003e\n        \u003cli\u003eUInt16\u003c/li\u003e\n        \u003cli\u003eUInt32\u003c/li\u003e\n        \u003cli\u003eUInt64\u003c/li\u003e\n      \u003c/ul\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n- compiles on Windows, macOS and Linux\n- compatible with code targeting ANSI C ([a GNU compiler][iso-c] supporting `-ansi` is required)\n\n **Note**\n A compiler supporting the C99 standard is required for building.\n\n- (since version 1.7) compatible with [CPM.cmake]. See [below](#cpm-integration) for a sample configuration.\n\nExamples\n--------\n**Using function macros (they wrap the \"member functions\")**\n```c\n#include \u003cstdio.h\u003e\n#include \u003cmoreinttypes/core.h\u003e //\u003c Make sure this comes last!\n\nInt32 i = integer(122333333);\n\n// access the underlying value . . .\nprintf(\"%d\\n\", i.value);\n// \"122333333\"\n\n// . . . but no direct assignment allowed!\n// i.value = 0;\n//\n// error: assignment of read-only member ‘value’\n//   i.value = 0;\n//           ^\n\n// let's set it to the value of a binary string\nfrom_string(i, \"10101010\", 2);\nprintf(\"New value: %d\\n\", i.value);\n// \"New value: 170\"\n\n// what's that in base-2?\nconst char* bin_str = as_binary(i);\nprintf(\"%s\\n\", bin_str);\n// \"1010 1010\"\n\nfrom_string(i, \"6\", 10);\nlong double f = factorial(i);\nprintf(\"%d! = %.0Lf\\n\", i.value, f);\n// \"6! = 720\"\n```\n\n**Using free functions**\n```c\n#include \u003cstdio.h\u003e\n#include \u003cmoreinttypes/utils.h\u003e\n\nint value = parse_int(\"10101010\", 2);\nprintf(\"%d\\n\", value);\n// \"170\"\n\nchar buf[16]  = { 0 };\nconst char* bin_str = binary_string(buf, 170);\nprintf(\"%s\\n\", bin_str);\n// \"1010 1010\"\n\nlong double f = factorial_of(6);\nprintf(\"6! = %.0Lf\\n\", f);\n// \"6! = 720\"\n```\n\n[CPM][CPM.cmake] integration \u003ca id=\"cpm-integration\" aria-label=\"CPM Integration\"\u003e\u003c/a\u003e\n-----------------\nAdd the following to your project's `CMakeLists.txt`:\n\n```cmake\ncmake_minimum_required (VERSION 3.14)\n\n# Download the 'get_cpm.cmake' module from https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.39.0/get_cpm.cmake\ninclude (get_cpm.cmake)\n\nproject (try-libmoreinttypes)\n\nCPMAddPackage (\"gh:rdipardo/libmoreinttypes#1.8.0\")\n\nadd_executable (main \"main.c\")\n\nadd_library (libmoreinttypes INTERFACE IMPORTED)\n\ntarget_link_libraries (main PUBLIC moreinttypes)\n\ntarget_include_directories (main\n    PUBLIC\n    \"${libmoreinttypes_SOURCE_DIR}/include\"\n)\n\nset_target_properties (main moreinttypes\n    PROPERTIES\n    RUNTIME_OUTPUT_DIRECTORY \"${PROJECT_SOURCE_DIR}/bin\"\n)\n```\n\nBuilding\n--------\n- **All environments require [cmake](https://cmake.org)**\n- (_optional_) [valgrind], to profile memory usage during unit tests\n- (_optional_) [pkg-config](https://packages.debian.org/sid/pkg-config), if available for your system\n- (_optional_) [doxygen], if you'd like a local copy of [the documentation][]\n\n**Windows** developers can use the [Visual C++ compiler][], edition 2015 or later.\n\nCompiling with the [MinGW][] toolchain or inside the [MSYS2][] environment will work also.\n\n**Linux** devs can use [gcc][] (version 4.9 and up) or [clang][] (version 3.8 and up).\n\n### Build options\n\u003ctable border=\"0\"\u003e\n  \u003ctr\u003e\n    \u003cth/\u003e\n    \u003cth/\u003e\n    \u003cth align=\"left\"\u003eDefault\u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003ccode\u003e-DMOREINTTYPES_BUILD_TESTS=OFF|ON\u003c/code\u003e\u003c/td\u003e\n    \u003ctd\u003ebuild and run unit tests\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003eON\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003ccode\u003e-DMOREINTTYPES_BUILD_EXAMPLES=OFF|ON\u003c/code\u003e\u003c/td\u003e\n    \u003ctd\u003ebuild sample programs\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003eOFF\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003ccode\u003e-DMOREINTTYPES_BUILD_STATIC=OFF|ON\u003c/code\u003e\u003c/td\u003e\n    \u003ctd\u003ebuild a static library\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003eOFF\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003ccode\u003e-DMOREINTTYPES_ENABLE_UBSAN=OFF|ON\u003c/code\u003e\u003c/td\u003e\n    \u003ctd\u003eenable the \u003ca href=\"https://developers.redhat.com/blog/2014/10/16/gcc-undefined-behavior-sanitizer-ubsan\" target=\"_blank\"\u003e\n      Undefined Behavior Sanitizer\u003c/a\u003e (GCC,Clang only)\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003eOFF\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003ccode\u003e-DMOREINTTYPES_RUN_DEMO=OFF|ON\u003c/code\u003e\u003c/td\u003e\n    \u003ctd\u003erun a sample program immediately after the build (requires \u003ccode\u003eMOREINTTYPES_BUILD_EXAMPLES\u003c/code\u003e)\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003eOFF\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003ccode\u003e-DMOREINTTYPES_CHECK_WITH_VALGRIND=OFF|ON\u003c/code\u003e\u003c/td\u003e\n    \u003ctd\u003erun a memory leak check with \u003ca href=\"https://valgrind.org\" target=\"_blank\"\u003e\n      valgrind\u003c/a\u003e, if installed \u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003eOFF\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n### Deprecated options (since [1.7.0])\n\u003ctable border=\"0\"\u003e\n  \u003ctr\u003e\n    \u003cth/\u003e\n    \u003cth align=\"left\"\u003eReplaced by...\u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003ccode\u003e-DBUILD_STATIC=OFF|ON\u003c/code\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003e-DMOREINTTYPES_BUILD_STATIC\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003ccode\u003e-DENABLE_UBSAN=OFF|ON\u003c/code\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003e-DMOREINTTYPES_ENABLE_UBSAN\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003ccode\u003e-DRUN_DEMO=OFF|ON\u003c/code\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003e-DMOREINTTYPES_RUN_DEMO\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003ccode\u003e-DWITH_VALGRIND=OFF|ON\u003c/code\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003ccode\u003e-DMOREINTTYPES_CHECK_WITH_VALGRIND\u003c/code\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nThe build steps are the same for all environments, with one exception:\n\n- if you're using the **Visual C++ compiler**, start the [Developer Command Prompt][]; all other users can simply log in to their usual shell\n- clone the main branch and enter the root directory at the command line: `cd libmoreinttypes`\n- make and enter the build directory: `mkdir cmake-build \u0026\u0026 cd cmake-build`\n- run: `cmake .. `, or (to use a certain [makefile generator][]) `cmake .. -G\"\u003cname_of_generator\u003e\"`\n\n**Note**\nIt's better to run `cmake .. -G\"NMake Makefiles\"` when using the Visual C++ compiler.\nThis will prevent `cmake` from choosing a [Visual Studio Generator][] by default.\n\n- run:\n\u003cdiv\u003e\u003c/div\u003e\n\n\n    make\n\nor, if using [MinGW][]:\n\n    mingw32-make\n\nor, if using [nmake][]:\n\n    nmake\n\n\nInstalling\n----------\nAs the admin user, run:\n\n    make install\n\nor\n\n    mingw32-make install\n\nor\n\n    nmake install\n\n\nAPI Documentation\n-----------------\nTo build the [the documentation] and serve it at `localhost:8000`, enter the `doxygen` directory and run:\n\n    ./gendocs\n\nor, on Windows,\n\n    .\\gendocs\n\n**Note**\nMake sure [doxygen] and [python] are installed and visible to your system's `PATH`.\n\n---\n**This project took inspiration from the following sources:**\n- the [C Object System](https://github.com/CObjectSystem/COS). Like this library, it strives to be compatible with ANSI/C89 while taking advantage of C99 features at compile time\n- Schreiner, A.-T. (1993). [Object-oriented programming\n  with ANSI-C](https://www.cs.rit.edu/~ats/books/ooc.pdf). You can read the full text of this obscure classic for free online\n\nLicense\n-------\nCopyright (c) 2020 Robert Di Pardo and Contributors. All rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification,\nare permitted provided that the following conditions are met:\n\n1. Redistributions of source code must retain the above copyright notice,\nthis list of conditions and the following disclaimer.\n\n2. Redistributions in binary form must reproduce the above copyright notice,\nthis list of conditions and the following disclaimer in the documentation\nand/or other materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\nAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\nIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\nARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE\nLIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\nDAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\nSERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\nCAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\nOR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE\nUSE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\n\n[CPM.cmake]: https://github.com/cpm-cmake/CPM.cmake/#readme\n[Visual C++ compiler]: https://docs.microsoft.com/en-us/cpp/build/vscpp-step-0-installation\n[Developer Command Prompt]: https://docs.microsoft.com/en-us/dotnet/framework/tools/developer-command-prompt-for-vs\n[MSYS2]: https://cmake.org/cmake/help/latest/generator/MSYS%20Makefiles.html#generator:MSYS%20Makefiles\n[MinGW]: https://cmake.org/cmake/help/latest/generator/MinGW%20Makefiles.html\n[nmake]: https://docs.microsoft.com/en-us/cpp/build/reference/running-nmake?view=msvc-160\n[gcc]: https://gcc.gnu.org\n[clang]: https://clang.llvm.org\n[valgrind]: https://valgrind.org/downloads\n[python]: https://www.python.org/downloads\n[doxygen]: https://www.doxygen.nl/index.html\n[makefile generator]: https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html#makefile-generators\n[Visual Studio Generator]: https://cmake.org/cmake/help/latest/generator/Visual%20Studio%2014%202015.html\n[the documentation]: https://rdipardo.github.io/libmoreinttypes\n[polymorphic function macros]: https://rdipardo.github.io/libmoreinttypes/d2/d46/group__int__fn__wrappers.html\n[1.7.0]: https://github.com/rdipardo/libmoreinttypes/commit/74e48d0\n[iso-c]: https://github.com/rdipardo/libmoreinttypes/blob/5355b132ebaeb939843587191859e10d26cd1080/include/moreinttypes/_compat.h","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frdipardo%2Flibmoreinttypes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frdipardo%2Flibmoreinttypes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frdipardo%2Flibmoreinttypes/lists"}