Skip to content

Commit 6bdb069

Browse files
authored
[docs]: warning for long, culong being OS-dependent (#25012)
Docs are routinely compiled on a different OS so often don't reflect reality of CT-conditionals. I bet there's a few of other places like this in the stdlib.
1 parent 7e6fa9e commit 6bdb069

File tree

1 file changed

+38
-7
lines changed

1 file changed

+38
-7
lines changed

lib/system/ctypes.nim

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,50 @@ type
1717
## supports. Currently this is `uint64`, but it is platform-dependent
1818
## in general.
1919

20-
when defined(windows):
20+
when defined(nimdoc):
21+
type
22+
# "Opaque" types defined only in the `nimdoc` branch to not show in error
23+
# messages in regular code with `clong` and `culong` resolving to base types
24+
ClongImpl = (when defined(windows): int32 else: int)
25+
CulongImpl = (when defined(windows): uint32 else: uint)
26+
clong* = ClongImpl
27+
## Represents the *C* `long` type, used for interoperability.
28+
##
29+
## Its purpose is to match the *C* `long` for the target
30+
## platform's Application Binary Interface (ABI).
31+
##
32+
## Typically, the compiler resolves it to one of the following Nim types
33+
## based on the target:
34+
## - `int32 <system.html#int32>`_ on Windows using MSVC or MinGW compilers.
35+
## - `int <system.html#int>`_ on Linux, macOS and other platforms that use the
36+
## LP64 or ILP32 `data models
37+
## <https://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models>`_.
38+
##
39+
## .. warning:: The underlying Nim type is an implementation detail and
40+
## should not be relied upon.
41+
culong* = CulongImpl
42+
## Represents the *C* `unsigned long` type, used for interoperability.
43+
##
44+
## Its purpose is to match the *C* `unsigned long` for the target
45+
## platform's Application Binary Interface (ABI).
46+
##
47+
## Typically, the compiler resolves it to one of the following Nim types
48+
## based on the target:
49+
## - `uint32 <system.html#uint32>`_ on Windows using MSVC or MinGW compilers.
50+
## - `uint <system.html#uint>`_ on Linux, macOS and other platforms that use the
51+
## LP64 or ILP32 `data models
52+
## <https://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models>`_.
53+
##
54+
## .. warning:: The underlying Nim type is an implementation detail and
55+
## should not be relied upon.
56+
elif defined(windows):
2157
type
2258
clong* {.importc: "long", nodecl.} = int32
23-
## This is the same as the type `long` in *C*.
2459
culong* {.importc: "unsigned long", nodecl.} = uint32
25-
## This is the same as the type `unsigned long` in *C*.
2660
else:
2761
type
2862
clong* {.importc: "long", nodecl.} = int
29-
## This is the same as the type `long` in *C*.
3063
culong* {.importc: "unsigned long", nodecl.} = uint
31-
## This is the same as the type `unsigned long` in *C*.
3264

3365
type # these work for most platforms:
3466
cchar* {.importc: "char", nodecl.} = char
@@ -51,8 +83,7 @@ type # these work for most platforms:
5183
## This is the same as the type `long double` in *C*.
5284
## This C type is not supported by Nim's code generator.
5385

54-
cuchar* {.importc: "unsigned char", nodecl, deprecated: "use `char` or `uint8` instead".} = char
55-
## Deprecated: Use `uint8` instead.
86+
cuchar* {.importc: "unsigned char", nodecl, deprecated: "Use `char` or `uint8` instead".} = char
5687
cushort* {.importc: "unsigned short", nodecl.} = uint16
5788
## This is the same as the type `unsigned short` in *C*.
5889
cuint* {.importc: "unsigned int", nodecl.} = uint32

0 commit comments

Comments
 (0)