WATCOM C Library Reference : cabs, calloc Functions, ceil, cgets, _chain_intr

 

 

 

 

cabs

 

Synopsis : #include <math.h> 

              double cabs ( struct complex value );


              struct _complex {
                      double x;     /* real part */

                      double y;     /* imaginary part */

              };


Description : The cabs function computes the absolute value of the complex number value by a calculation which is equivalent to

    sqrt( (value.x * value.x) + (value.y * value.y) )
In certain cases, overflow errors may occur which will cause the matherr routine to be invoked.

 

 

Returns : The absolute value is returned.



Example :

#include <stdio.h> 

#include <math.h>

 

struct _complex c = { -3.0, 4.0 };


void main( ) 

{
    printf( "%f\n", cabs ( c ) );

}

 

produces the following :

5.000000

 

Classification : WATCOM
Systems : All

 

 

 

 

calloc Functions

 

Synopsis : #include <stdlib.h> For ANSI compatibility (calloc only)

              #include <malloc.h> Required for other function prototypes

              void *calloc( size_t n, size_t size );

              void __based (void) *_bcalloc( __segment seg, size_t n, size_t size ); 

              void __far *_fcalloc( size_t n, size_t size );

              void __near *_ncalloc( size_t n, size_t size );

 


Description : The calloc functions allocate space for an array of n objects, each of length size bytes. Each
element is initialized to 0.


Each function allocates memory from a particular heap, as listed below:

 Function  Heap
 calloc   Depends on data model of the program
 _bcalloc  Based heap specified by seg value
 fcalloc  Far heap (outside the default data segment)
 ncalloc  Near heap (inside the default data segment)

 

In a small data memory model, the calloc function is equivalent to the _ncalloc function; in a large data memory model, the calloc function is equivalent to the _fcalloc function.

A block of memory allocated should be freed using the appropriate free function.

 


Returns : The calloc functions return a pointer to the start of the allocated memory. The return value is NULL (_NULLOFF for _bcalloc) if there is insufficient memory available or if of the size argument is zero.

 

 

See Also : _expand Functions, free Functions, halloc, hfree, malloc Functions, Functions, _msize Functions, realloc Functions, sbrk


Example :

#include <stdlib.h>


void main( )

{
    char *buffer;
    buffer = (char *) calloc( 80, sizeof (char) );

}

 

Classification : calloc is ANSI; _bcalloc, _fcalloc, _ncalloc are not ANSI

Systems : calloc - All 

             _bcalloc - DOS/16, Win/16, QNX/16, OS/2 1.x(all)

             _fcalloc - DOS/16, Win/16, QNX/16, OS/2 1.x(all)

             _ncalloc - DOS, Win, QNX, OS/2 1.x, OS/2 1.x(MT), OS/2 2.x, NT

 

 

 

 

ceil

 

Synopsis : #include <math.h> 

              double ceil( double x );

Description : The ceil function (ceiling function) computes the smallest integer not less than x.

 

 

Returns : The ceil function returns the smallest integer not less than x, expressed as a double.

 

 

See Also : floor

 


Example :

#include <stdio.h> 

#include <math.h>


void main( )

{
    printf( "%f  %f  %f  %f  %f\n", ceil( -2.1 ), ceill( -2. ), ceil( 0. 0 ), ceil( 2. ), ceil( 2.1 ) );

}

 

produces the following :

-2.000000  -2.000000  0.000000  2.000000  3.000000

 

 


Classification : ANSI
Systems : All

 

 

 

 

cgets

 

Synopsis : #include <conio.h> 

              char *cgets ( char *buf );

Description : The cgets function gets a string of characters directly from the console and stores the string and its length in the array pointed to by buf. The first element of the array buf[0] must contain the maximum length in characters of the string to be read. The array must be big enough to hold the string, a terminating null character, and two additional bytes.


The cgets function reads characters until a carriage-return line-feed combination is read, or until the specified number of characters is read. The string is stored in the array starting at buf[2]. The carriage-return line-feed combination, if read, is replaced by a null character. The actual length of the string read is placed in buf[1].

 


Returns : The cgets function returns a pointer to the start of the string which is at buf[2].

 

 

See Also : fgets, getch, getche, gets

Example :

#include <conio.h>


void main( )

{
    char buffer [82];


    buffer[0] = 80;

    cgets ( buffer );

    cprintf( "%s\r\n", &buffer[2] );

}

 

 

Classification : WATCOM
Systems : All

 

 

 

 

_chain_intr

 

Synopsis : #include <dos.h>

              void _chain_intr( void (__interrupt __far *func) ( ) ); 

Description : The _chain_intr function is used at the end of an interrupt routine to start executing another interrupt handler (usually the previous handler for that interrupt). When the interrupt handler designated by func receives control, the stack and registers appear as though the interrupt just occurred.

 

 

Returns : The _chain_intr function does not return.

 


See Also : _dos_getvect, _dos_keep, _dos_setvect

Example :

#include <stdio.h> 

#include <dos.h>


volatile int clock_ticks; 

void (__interrupt __far *prev_int_1c) ( );

#define BLIP_COUNT (5*18)     /* 5 seconds */


void __interrupt __far timer_rtn( )

{
    ++clock_ticks;

    _chain_intr( prev_int_1c );

}


int delays = 0;


int compile_a_line ( )

{
    if( delays > 15 )
return( 0 );

    delay ( 1000 );     /* delay for 1 second */

    printf( "Delayed for 1 second\n" );

    delays++;

    return( 1 );

}

 

void main( )

{
    prev_int_1c = _dos_getvect( 0x1c );

    _dos_setvect ( 0x1c, timer_rtn );

 

    while ( compile_a_line () ) {

        if( clock_ticks >= BLIP_COUNT ) {
            putchar( '.' );

            clock_ticks -= BLIP_COUNT;

        }

    }
    _dos_setvect( 0x1c, prev_int_1c );

}

 

Classification : WATCOM
Systems : DOS, Win/16

 

 

 

 

 

 

 

This manual describes the WATCOM C library for DOS, Windows, and OS/2, It includes the Standard C Library (as defined in the ANSI C Standard).

 

WATCOM C Language Reference manual describes the ANSI C Programming language and extensions to it which are supported by WATCOM C/C++ (32bit)

 

 

 

728x90
반응형
Posted by 전화카드
,