ctypes.nim 3.6 KB

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