https://github.com/alexfru/typetraitsinc
Type Traits in C
https://github.com/alexfru/typetraitsinc
c endianness self-descriptive traits types
Last synced: about 1 year ago
JSON representation
Type Traits in C
- Host: GitHub
- URL: https://github.com/alexfru/typetraitsinc
- Owner: alexfru
- Created: 2014-09-17T11:19:16.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2014-09-25T04:45:35.000Z (almost 12 years ago)
- Last Synced: 2023-04-03T17:01:14.983Z (over 3 years ago)
- Topics: c, endianness, self-descriptive, traits, types
- Size: 180 KB
- Stars: 8
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.txt
Awesome Lists containing this project
README
The presentation slides and the sample code (TBD) demonstrate how to implement
type traits in C somewhat similar to those that can be implemented in C++ with
templates. This is achieved through construction of "self-descriptive types".
The technique lets the programmer write more generic C code that is still type-
aware and abstract away and hide most of the type-specific machinery while also
making coding less error-prone.
As an example of the technique the presentation shows how one can greatly
simplify handling of byte order (AKA endianness) conversions by introducing
types like little_endian_uint32_t and big_endian_uint16_t and just 2 macros
(EGET() and ESET()) that the programmer has to use to achive the goal as opposed
to using the following battery of similarly looking and easy-to-confuse macros:
htonl(), ntohl(), htons() and ntohs().