Skip to content

Documentation on fun argument conversion is incorrect #683

@HertzDevil

Description

@HertzDevil

The docs say:

Note that there are no implicit conversions (except to_unsafe, which is explained later) when invoking a C function: you must pass the exact type that is expected. For integers and floats you can use the various to_... methods.

But this is not true:

lib LibC
  alias Int = Int32
  fun exit(status : Int) : NoReturn
end

LibC.exit(69_u8)   # okay
LibC.exit(69_i128) # okay

More surprising is that it is okay to pass a BigInt here too, but not its unsafe counterpart:

require "big"

LibC.exit(69.to_big_i)           # okay
LibC.exit(69.to_big_i.to_unsafe) # Error: argument 'x0' of 'LibC#exit' must be Int32, not Pointer(LibGMP::MPZ)

So something else must be going on.

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