Skip to content

IntClone

Description

Create a deep copy of an integer.

Parameters

Name Direction Description
value in Integer to clone

Usage example (from documentation)

  Int copy = IntClone(&value);

Success

Returns an independent deep copy of value’s bit-vector, normalised, and bound to value’s allocator. value is not modified.

Failure

Returns a freshly initialised empty Int bound to value’s allocator on allocation failure during the bit-vector copy. The caller cannot distinguish that from a true zero result; use IntTryClone directly when explicit failure propagation is required.

Usage example (Cross-references)

Usage examples (Cross-references)
    
    static SignedInt sint_clone(SignedInt *value) {
        SignedInt clone = {.negative = value->negative, .magnitude = IntClone(&value->magnitude)};
        sint_normalize(&clone);
        return clone;
    }
    
    Int IntClone(const Int *value) {
        Int clone;
        }
    
        current = IntClone(value);
        if (IntIsZero(&current)) {
            return false;
    
    bool test_int_clone(void) {
        WriteFmt("Testing IntClone\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        Int original = IntFromBinary("1011", &alloc.base);
        Int clone    = IntClone(&original);
    
        bool result = IntEQ(&clone, &original);
    
    bool test_int_clone_inherits_allocator_config(void) {
        WriteFmt("Testing IntClone allocator inheritance\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
        BitVecPush(&original.bits, true);
    
        Int clone = IntClone(&original);
    
        bool result =
Last updated on