TYPES is a simple, header-only C library designed to provide types with sizes. This project targets both Windows and GNU/Linux (32-bit and 64-bit) platforms. The library aims to help developers easily specify the size of a type instead of relying on the compiler/OS/CPU architecture and macros.
- Features
- Requirements
- Usage
- Dependency
- Roadmap
- Contributing
- Naming Convention
- License
- Project Status
- Contact
- Versioning
- Changelog
-
Type Definitions
- Added comprehensive type definitions:
- Boolean:
bool
- Signed integers:
i8
,i16
,i32
,i64
,imin
,imax
- Unsigned integers:
u8
,u16
,u32
,u64
,umin
,umax
,usize
- Other types:
byte
,charcode
- Floating points:
f32
,f64
,fmin
,fmax
- General purpose:
any
- Boolean:
- Added comprehensive type definitions:
-
Type Pretend Macros
TYPES_PRETEND_64BIT_INTEGER
: Makes 64-bit types act as 32-bit types for compatibility purposes.
-
Integer and Pointer Size Checks
TYPES_64BIT_INTEGER
: Checks if the compiler, OS, and CPU support 64-bit integers.TYPES_32BIT_INTEGER
: Checks if the compiler, OS, and CPU support 32-bit integers.TYPES_64BIT_POINTER
: Checks if the compiler, OS, and CPU support 64-bit pointers.TYPES_32BIT_POINTER
: Checks if the compiler, OS, and CPU support 32-bit pointers.
-
Type Boundaries and Sizes
MIN_<TYPE_NAME>
: Macro to get the minimum value of a type.MAX_<TYPE_NAME>
: Macro to get the maximum value of a type.SZ_<TYPE_NAME>
: Macro to get the size of a type.
-
Format Specifiers and Type Casts
FMTSP_<TYPE_NAME>
: Macro to get standard C format specifiers.FSBTC_<TYPE_NAME>
: Function-like macro to type cast the library types.
To get started with this project, download and install the following.
-
Download and install git
-
If you use Windows, then go to this link and download and install the suitable version.
-
If you use any stable version of Debian/Ubuntu then run this command in your terminal
sudo apt-get install git
-
If you use macOS then install homebrew if you don't already have it, then run this command in your terminal
brew install git
-
-
Run the command to clone this repository
git clone https://github.com/KumarjitDas/types.git
-
Download and install a C compiler
-
If you use Windows 8/10/11 then download Visual Studio 2017/2019/2022 from this link or download and install a suitable version of clang from this link. For gcc, use the suitable MinGW version from this link.
-
If you use any stable version of Debian/Ubuntu then run these commands in your terminal to download and install clang and gcc compilers
sudo apt install clang
sudo apt install gcc
-
In macOS, clang is the default C compiler. To download and install gcc, run this command in your terminal
brew install gcc
-
-
For building on Linux 32-bit targets on a 64-bit platform,
gcc-multilib
must be installed:sudo apt install gcc-multilib
-
Download and install CMake
The types library depends on the kdapi library. Ensure that you have the kdapi library available in your project. If you do not provide the location of the kdapi CMake targets, the types library will attempt to download the kdapi library and place it in the external directory inside the build tree.
- Download the
kdapi
library from the official repository or source. - Provide the cmake-targets path in either inside root cmake file or in the command line
-
In CMake file
# ... list(APPEND CMAKE_PREFIX_PATH path/to/kdapi/lib/cmake) # ...
-
In command line as an argument
cmake ... -DCMAKE_PREFIX_PATH=path/to/kdapi/lib/cmake ...
-
-
Download the latest release of the project according to your system specification.
-
For CMake projects add the types library cmake directory path to the
CMAKE_PREFIX_PATH
variable.-
In CMake file
# ... list(APPEND CMAKE_PREFIX_PATH path/to/types/lib/cmake) # ...
-
In command line as an argument
cmake ... -DCMAKE_PREFIX_PATH=path/to/types/lib/cmake ...
-
-
Include the types.h header file in your C project to use KDAPI.
#include "types.h"
-
To build the project from source using CMake you have to provide target platform information (
KDAPI_TARGET_OS
andKDAPI_TARGET_ARCH
. For example:cmake -DKDAPI_TARGET_OS=windows -DKDAPI_TARGET_ARCH=x64 -G Ninja -S path/to/types -B path/to/build
You can find all the examples here. Here's a demo:
#include <stdio.h>
#include "types.h"
int main() {
printf("TYPES Version: %s\n", TYPES_VERSION_STR);
i8 val8i = 128;
u32 val32u = 654321;
printf("val8i: " FMTSP_I8 ", val32u = " FMTSP_U32 "\n", FSBTC_I8(val8i), FSBTC_U32(val32u));
return 0;
}
See the open issues for a list of proposed features/functionalities (and known issues).
The list of features and functions implemented till now is given in Project Status.
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
-
Fork this project [types]
-
Create your Feature Branch
git checkout -b feature/AmazingFeature
-
Commit your Changes
git commit -m 'Added some AmazingFeature'
-
Push to the Branch
git push origin feature/AmazingFeature
-
Create a pull request
The TYPES project follows a consistent naming convention to ensure readability and maintainability. Here are the key aspects of the naming convention used:
-
Macro Names: Macro names are written in uppercase letters with underscores separating words. They typically start with the prefix
KD_
. -
Examples:
KD_COMPILER_GCC
,KD_OS_LINUX
,KD_CPU_X86_64
,KD_VERSION_MAJOR
-
Macro Definitions:
- Macro names are written in uppercase letters. They typically start with the prefix
TYPES_
. - Words are separated by underscores (
_
). - Example:
TYPES_VERSION_MAJOR
,TYPES_DEFINED_TYPE_BOOL
.
- Macro names are written in uppercase letters. They typically start with the prefix
-
Type Definitions:
- Type names are in lowercase.
- Use of prefixes for type groups, such as
kd_types__type_
for internal types. - Example:
kd_types__type_i64_
,bool
,i8
.
-
Enums:
- Enum names follow a similar lowercase pattern, with names indicating boolean values.
- Example:
kd_types__type_bool_
with valuesfalse
andtrue
.
-
Function-like Macros:
- Macros that behave like functions are in uppercase with parameters in parentheses.
- Example:
TYPES_I64(x)
,TYPES_U32(x)
,FSBTC_U32(x)
.
-
Constant Values:
- Constants follow the uppercase convention and often include type indications.
- Example:
MIN_I8
,MAX_I32
,SZ_BOOL
,FMTSP_I8
.
This project is distributed under the BSD 2-Clause License. See LICENSE for more information.
List of functionalities/features implemented so far:
- Type definitions:
bool
,i8
,i16
,i32
,i64
,imin
,imax
,u8
,u16
,u32
,u64
,umin
,umax
,usize
,byte
,charcode
,f32
,f64
,fmin
,fmax
, andany
. - Macro
TYPES_PRETEND_64BIT_INTEGER
: Makes 64-bit types act as 32-bit types. - Macro
TYPES_DEFINED_TYPE_<TYPE_NAME>
: Checks if a type is defined. - Macro
TYPES_DEFINED_TYPEVAL_<VALUE_NAME>
: Checks if a constant value of a type is defined. - Macro
TYPES_64BIT_INTEGER
: Checks if the compiler, OS, and CPU support 64-bit integers. - Macro
TYPES_32BIT_INTEGER
: Checks if the compiler, OS, and CPU support 32-bit integers. - Macro
TYPES_64BIT_POINTER
: Checks if the compiler, OS, and CPU support 64-bit pointers. - Macro
TYPES_32BIT_POINTER
: Checks if the compiler, OS, and CPU support 32-bit pointers. - Macro
MIN_<TYPE_NAME>
: Gets the minimum value of a type. - Macro
MAX_<TYPE_NAME>
: Gets the maximum value of a type. - Macro
SZ_<TYPE_NAME>
: Gets the size of a type. - Macro
FMTSP_<TYPE_NAME>
: Gets compatible standard C format specifier of a type. - Macro
FMTSP_<TYPE_NAME>(x)
: Gets suitable type cast of a type. - Build Configuration: CMake configuration files for shared and static builds.
- Example Programs: Examples demonstrating library usage.
Twitter: @kumarjitdas1999
LinkedIn: Kumarjit Das
E-mail: kumarjitdas1999@gmail.com
Project link: TYPES
This project uses MAJOR, MINOR, and PATCH version numbers for versioning (vMAJOR.MINOR.PATCH).
- MAJOR version number indicates new changes which may be incompatible with older versions.
- MINOR version number indicates addition of backwards-compatible features.
- PATCH version number indicates backwards-compatible bug fixes, or minor mistake fixes like spelling, character cases, punctuations, and indentation.
The Changelog file contains all the information about the changes made to this project till now.
You can also view the raw version.