BASIC_TYPES.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #ifndef BASIC_TYPES_HEADER
  2. #define BASIC_TYPES_HEADER
  3. // at start, this library expects that the system
  4. // follows the 1 byte = 8 bits "accepted convention"
  5. #ifndef CHAR_BIT
  6. #define CHAR_BIT 8
  7. #endif
  8. // minimum integers
  9. // char is the fundamental space unit
  10. // it is expected to be 1 byte long
  11. // typedef char char;
  12. typedef unsigned char byte;
  13. #define CHAR_SIZE sizeof(char)
  14. #define BYTE_SIZE sizeof(byte)
  15. // largest integers. I hope
  16. // they are at least 32 bits long
  17. typedef long long smax;
  18. typedef unsigned long long umax;
  19. #define SMAX_SIZE sizeof(smax)
  20. #define UMAX_SIZE sizeof(umax)
  21. // max float type (I expect it to be a 32 or 64 bits float)
  22. // won't use long double since I don't want to deal with
  23. // 12 bytes doubles implemented by some compilers
  24. typedef double fmax;
  25. #define FMAX_SIZE sizeof(fmax)
  26. // custom boolean type
  27. typedef char bool;
  28. #define BOOL_SIZE sizeof(bool)
  29. #define true 1
  30. #define false 0
  31. // NOTE: enums will be declared in UPPERCASE
  32. // to be able to distinguish them from
  33. // other variable types easily
  34. // var_basic_types enum
  35. // the first variable types enum
  36. // all other variable types enums will continue this one
  37. // so it is like an "extensible" variable type enum
  38. typedef enum
  39. {
  40. VAR_CHAR,
  41. VAR_BYTE,
  42. VAR_SMAX,
  43. VAR_UMAX,
  44. VAR_FMAX,
  45. VAR_BOOL,
  46. VAR_BASIC_TYPES
  47. } var_basic_types;
  48. // mask enum as an integer type for
  49. // variable type function arguments
  50. typedef var_basic_types var_type;
  51. // creating and destroying is not
  52. // necessary with these simple data types
  53. umax print_byte_dec(byte * src, umax size);
  54. umax print_byte_hex(byte * src, umax size);
  55. umax print_char(byte * src, umax size);
  56. umax print_umax_dec(byte * src, umax size);
  57. umax print_umax_hex(byte * src, umax size);
  58. umax print_smax(byte * src, umax size);
  59. umax print_fmax(byte * src, umax size);
  60. umax print_bool(byte * src, umax size);
  61. #include "BASIC_TYPES.c"
  62. #endif // BASIC_TYPES_HEADER