Skip to content

questionable csize definition in system.nim #12187

@jangko

Description

@jangko

I'm sure the story of csize is different from cstring.

Current definition

csize* {.importc: "size_t", nodecl.} = int
    ## This is the same as the type ``size_t`` in *C*.

what interesting is the comment claims csize has the same type as size_t in C.
in reality, when we take a look at C or CPP header file, especially stddef.h, they agree it should be an unsigned int.

CPP doc and GNU C doc also agree size_t should be unsigned int.

if csize is an int, it implies csize can be negative or cannot exceed high(int) which is questionable.

also if it is used in FFI, it can be a subtle bug, very difficult to track down.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions