Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ calloc(3C) — DG/UX 4.00

Media Vault

Software Library

Restoration Projects

Artifacts Sought



                                                               calloc(3C)



        _________________________________________________________________
        calloc                                                   function
        Allocate blocks of memory and fill them with zeros.
        _________________________________________________________________


        Calling Sequence

        char *ptr, *calloc();
        unsigned int n, size;
        ptr = calloc(n, size);



          where   n is the number of bytes needed for the object.

                  size is the number of objects to allocate.



        Description

        Use the calloc function to allocate blocks of memory and fill
        them with zeros.  The function will allocate a total of (n *
        size) bytes of memory, and then zero each byte.

        Any pointer that the calloc function returns will be a word-
        aligned byte pointer.  After the appropriate conversion, you can
        use the result as a pointer to any item.

        The include file stdio.h defines the calloc function.


        Returns

        The calloc function returns a pointer to the allocated block, or
        (char *)0 if it cannot allocate that much memory from the heap.


        Related Functions

        See also the alloc, alloca, malloc, and realloc functions.


        Example

        /* Program test for the calloc() function */

        #include <stdio.h>





        DG/UX 4.00                                                 Page 1
               Licensed material--property of copyright holder(s)





                                                               calloc(3C)



        char    *ptr, *calloc();
        unsigned int n, size;


        main(argc, argv)
        int     argc;
        char    *argv[];
        {
            size = atou(argv[1]);
            n = atou(argv[2]);
            ptr = calloc(n, size);
            printf("Size of %d bytes x %d objects =\n", size, n);
            printf("an allocation %d in the block %o.\n", size * n, ptr);
        }

        A call to the program test with the input numbers 64 and 8
        generates the output

        Size of 64 bytes x 8 objects =
        an allocation 512 in the block 34003702770.

        The block location will vary with execution.
































        DG/UX 4.00                                                 Page 2
               Licensed material--property of copyright holder(s)



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026