Skip to content

[enhancement] add C style casts #155

@A60AB5450353F40E

Description

@A60AB5450353F40E

Currently some casts will actually call conversion like int() resulting in compiled bytecode using OP_BIN2NUM.

In some cases, when the user knows that the hex will be a valid script number this will be terribly wasteful.

Consider this:

int a=1;
bytes1 b=0x01;
require((bytes) a == b);

it would compile to OP_1 OP_1 OP_EQUALVERIFY

while

int a=1;
bytes1 b=0x01;
require(a == (int) b);

would compile to OP_1 OP_1 OP_NUMEQUALVERIFY.

What if b is not a valid int encoding? Then still compile the same but compiled Script would fail due to OP_NUMEQUALVERIFY erroring.

Sub-issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    cashc-compilerRelates to the cashc compiler

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions