'_memavl func'에 해당되는 글 1건

  1. 2021.07.20 Watcom C Library : max, mblen, mbstowcs, mbtowc, _memavl

 

 

Watcom C Library Reference : max, mblen, mbstowcs, mbtowc, _memavl

 

 

 

 

max

 

Synopsis : #include <stdlib.h> 

              #define max (a, b) ( ( (a) > (b) ) ? (a) : (b) )

 


Description :  The max macro will evaluate to be the greater of two values. It is implemented as follows.

                  #define max (a, b) ( ( (a) > (b) ) ? (a) : (b) )

 

 

Returns : The max macro will evaluate to the larger of the two values passed.

 

 

See Also : min

 


Example :

#include <stdio.h> 

#include <stdlib.h>


void main( )

{
    int     a;


    /*  The following line will set the variable "a" to 10 * since 10 is greater than 1  */
    a = max( 1, 10 );

    printf( "The value is: %d\n", a );

}

 

Classification : WATCOM
Systems : All

 

 

 

 

 

mblen

 

Synopsis : #include <stdlib.h> 

              int mblen ( const char *s, size_t n );

 


Description :  The mblen function determines the number of bytes comprising the multibyte character pointed to by s. At most n bytes of the array pointed to by s will be examined.

 

 

Returns : If s is a NULL pointer, the mblen function returns zero if multibyte character encodings do not have state-dependent encoding, and non-zero otherwise. If s is not a NULL pointer, the mblen function returns:

 

 Value  Meaning
 0  if s points to the null character
 len  the number of bytes that comprise the multibyte character (if the next n or fewer bytes form a valid multibyte character)
 -1  if the next n bytes do not form a valid multibyte character

 

 

See Also : mbtowc, mbstowcs, wctomb, wcstombs

 


Example :

#include <stdio.h> 

#include <stdlib.h>


void main( )

{
    int     len; 

    char   *mbs = "string";


    printf( "Character encodings do %shave "
           "state-dependent encoding\n",

           ( mblen ( NULL, 0 ) ) ? " " : "not " );


    len = mblen( "string", 6 );

    if ( len != -1 ) {
        mbs [len] = '\0';

        printf( "Multibyte char '%s' (%d) \n", mbs, len ) ;

    }

}

 


produces the following :
Character encodings do not have state-dependent encoding Multibyte char 's' (1)

 

Classification : ANSI
Systems : All

 

 

 

 

 

mbstowcs

 

Synopsis : #include <stdlib.h> 

              size_t mbstowcs( wchar_t *pwcs, const char *s, size_t n );

 


Description : The mbstowcs function converts a sequence of multibyte characters pointed to by s into their corresponding wide character codes and stores not more than n codes into the array pointed to by pwcs. The mbstowcs function does not convert any multibyte characters beyond the null character. At most n elements of the array pointed to by pwcs will be modified.

 

 

Returns : If an invalid multibyte character is encountered, the mbstowcs function returns (size_t)-1. Otherwise, the mbstowcs function returns the number of array elements modified, not including the terminating zero code if present.

 

 

See Also : mblen, mbtowc, wctomb, wcstombs

 


Example :

#include <stdio.h> 

#include <stdlib.h>


void main( )

{
    char     *wc = "string";

    wchar_t  wbuffer[50];

    int        i, len;


    len = mbstowcs ( wbuffer, wc, 50 );

    if( len != -1 ) {
        wbuffer[len] = '\0';

        printf( "%s (%d)\n", wc, len );

        for( i = 0; i < len; i++ )
            printf( "/%4.4x", wbuffer[i] );

        printf("\n" );

    }

}

 


produces the following :
string (6) 

/0073/0074/0072/0069/006e/0067

 

Classification : ANSI
Systems : All

 

 

 

 

 

mbtowc

 

Synopsis : #include <stdlib.h> 

              int mbtowc( wchar_t *pwc, const char *s, size_t n );

 


Description : The mbtowc function converts a single multibyte character pointed to by s into the wide character code that corresponds to that multibyte character. The code for the null character is zero. If the multibyte character is valid and pwc is not a NULL pointer, the code is stored in the object pointed to by pwc. At most n bytes of the array pointed to by s will be examined.

 

 

Returns : If s is a NULL pointer, the mbtowc function returns zero if multibyte character encodings do not have state-dependent encoding, and non-zero otherwise. If s is not a NULL pointer, the mbtowc function returns:

 

 Value  Meaning
 0  if s points to the null character
 len  the number of bytes that comprise the multibyte character (if the next n or fewer bytes form a valid multibyte character)
 -1  if the next n bytes do not form a valid multibyte character

 

 

See Also : mblen, wctomb, mbstowcs, wcstombs

 


Example :

#include <stdio.h> 

#include <stdlib.h>


void main( )

{
    char     *wc = "string";

    wchar_t  wbuffer[10];

    int        i, len;


    printf( "Character encodings do %shave"
           "state-dependent encoding\n",

           ( mbtowc ( wbuffer, NULL, 0)) ? "" : "not " );


    len = mbtowc ( wbuffer, wc, 2 );

    wbuffer[len] = '\0';

    printf( "%s (%d) \n", wc, len );

    for( i = 0; i < len; i++ )
        printf( "/%4.4x", wbuffer[i] );

    printf( "\n" );

}

 


produces the following :
Character encodings do not have state-dependent encoding string (1)

/0073

 

Classification : ANSI
Systems : All

 

 

 

 

 

_memavl

 

Synopsis : #include <malloc.h> 

              size_t _memavl( void );

 


Description : The memavl function returns the number of bytes of memory available for dynamic memory allocation in the near heap (the default data segment). In the tiny, small and medium memory models, the default data segment is only extended as needed to satisfy requests for memory allocation. Therefore, you will need to call _nheapgrow in these memory models before calling _memavl in order to get a meaningful result.

 

The number returned by _memavl may not represent a single contiguous block of memory. Use the _memmax function to find the largest contiguous block of memory that can be allocated.

 

 

Returns : The _memavl function returns the number of bytes of memory available for dynamic memory allocation in the near heap (the default data segment).

 

 

See Also : calloc Functions, _freect, _memmax, _heapgrow Functions, malloc Functions, realloc Functions

 


Example :

#include <stdio.h> 

#include <malloc.h>


void main( )

{
    char     *p;

    char     *fmt = "Memory available = %u\n";


    printf( fmt, _memavl( ) );

    _nheapgrow( );

    printf( fmt, memavl( ) );

    p = (char *) malloc( 2000 );

    printf( fmt, memavl( ) );

}

 


produces the following :
Memory available = 0

Memory available = 62732

Memory available = 60730

 

Classification : WATCOM
Systems : All

 

 

 

 

 

 

 

 

 

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 전화카드
,