Ignore:
Timestamp:
Apr 18, 2020, 9:08:12 AM (4 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
692e6f1
Parents:
899dfbb
Message:

add setter routines for sticky operations, add allocation size to header

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/stdlib.cfa

    r899dfbb r76e2113  
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Mar 31 13:26:46 2020
    13 // Update Count     : 495
     12// Last Modified On : Thu Apr 16 22:43:33 2020
     13// Update Count     : 498
    1414//
    1515
     
    3737        } // alloc_set
    3838
    39         T * alloc_set( T ptr[], size_t dim, T fill ) { // realloc array with fill
     39        T * alloc_set( T ptr[], size_t dim, T fill ) {          // realloc array with fill
    4040                size_t olen = malloc_usable_size( ptr );                // current allocation
    4141                void * nptr = (void *)realloc( (void *)ptr, dim * sizeof(T) ); // C realloc
    4242                size_t nlen = malloc_usable_size( nptr );               // new allocation
    4343                if ( nlen > olen ) {                                                    // larger ?
    44                         for ( i; dim ) { memcpy( &ptr[i], &fill, sizeof(T) ); } // initialize with fill value
     44                        for ( i; malloc_size( ptr ) / sizeof(T) ~ dim ) {
     45                                memcpy( &ptr[i], &fill, sizeof(T) );    // initialize with fill value
     46                        } // for
    4547                } // if
    4648                return (T *)nptr;
Note: See TracChangeset for help on using the changeset viewer.