ctypes.nim 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. ## Some type definitions for compatibility between different
  2. ## backends and platforms.
  3. type
  4. BiggestInt* = int64
  5. ## is an alias for the biggest signed integer type the Nim compiler
  6. ## supports. Currently this is `int64`, but it is platform-dependent
  7. ## in general.
  8. BiggestFloat* = float64
  9. ## is an alias for the biggest floating point type the Nim
  10. ## compiler supports. Currently this is `float64`, but it is
  11. ## platform-dependent in general.
  12. when defined(js):
  13. type BiggestUInt* = uint32
  14. ## is an alias for the biggest unsigned integer type the Nim compiler
  15. ## supports. Currently this is `uint32` for JS and `uint64` for other
  16. ## targets.
  17. else:
  18. type BiggestUInt* = uint64
  19. ## is an alias for the biggest unsigned integer type the Nim compiler
  20. ## supports. Currently this is `uint32` for JS and `uint64` for other
  21. ## targets.
  22. when defined(windows):
  23. type
  24. clong* {.importc: "long", nodecl.} = int32
  25. ## This is the same as the type `long` in *C*.
  26. culong* {.importc: "unsigned long", nodecl.} = uint32
  27. ## This is the same as the type `unsigned long` in *C*.
  28. else:
  29. type
  30. clong* {.importc: "long", nodecl.} = int
  31. ## This is the same as the type `long` in *C*.
  32. culong* {.importc: "unsigned long", nodecl.} = uint
  33. ## This is the same as the type `unsigned long` in *C*.
  34. type # these work for most platforms:
  35. cchar* {.importc: "char", nodecl.} = char
  36. ## This is the same as the type `char` in *C*.
  37. cschar* {.importc: "signed char", nodecl.} = int8
  38. ## This is the same as the type `signed char` in *C*.
  39. cshort* {.importc: "short", nodecl.} = int16
  40. ## This is the same as the type `short` in *C*.
  41. cint* {.importc: "int", nodecl.} = int32
  42. ## This is the same as the type `int` in *C*.
  43. csize_t* {.importc: "size_t", nodecl.} = uint
  44. ## This is the same as the type `size_t` in *C*.
  45. clonglong* {.importc: "long long", nodecl.} = int64
  46. ## This is the same as the type `long long` in *C*.
  47. cfloat* {.importc: "float", nodecl.} = float32
  48. ## This is the same as the type `float` in *C*.
  49. cdouble* {.importc: "double", nodecl.} = float64
  50. ## This is the same as the type `double` in *C*.
  51. clongdouble* {.importc: "long double", nodecl.} = BiggestFloat
  52. ## This is the same as the type `long double` in *C*.
  53. ## This C type is not supported by Nim's code generator.
  54. cuchar* {.importc: "unsigned char", nodecl, deprecated: "use `char` or `uint8` instead".} = char
  55. ## Deprecated: Use `uint8` instead.
  56. cushort* {.importc: "unsigned short", nodecl.} = uint16
  57. ## This is the same as the type `unsigned short` in *C*.
  58. cuint* {.importc: "unsigned int", nodecl.} = uint32
  59. ## This is the same as the type `unsigned int` in *C*.
  60. culonglong* {.importc: "unsigned long long", nodecl.} = uint64
  61. ## This is the same as the type `unsigned long long` in *C*.
  62. type
  63. ByteAddress* = int
  64. ## is the signed integer type that should be used for converting
  65. ## pointers to integer addresses for readability.
  66. cstringArray* {.importc: "char**", nodecl.} = ptr UncheckedArray[cstring]
  67. ## This is binary compatible to the type `char**` in *C*. The array's
  68. ## high value is large enough to disable bounds checking in practice.
  69. ## Use `cstringArrayToSeq proc <#cstringArrayToSeq,cstringArray,Natural>`_
  70. ## to convert it into a `seq[string]`.
  71. when not defined(nimPreviewSlimSystem):
  72. # pollutes namespace
  73. type
  74. PFloat32* {.deprecated: "use `ptr float32`".} = ptr float32
  75. ## An alias for `ptr float32`.
  76. PFloat64* {.deprecated: "use `ptr float64`".} = ptr float64
  77. ## An alias for `ptr float64`.
  78. PInt64* {.deprecated: "use `ptr int64`".} = ptr int64
  79. ## An alias for `ptr int64`.
  80. PInt32* {.deprecated: "use `ptr int32`".} = ptr int32
  81. ## An alias for `ptr int32`.