Chapter Contents

Previous

Next
memcmpp

memcmpp



Compare Two Blocks of Memory with Padding

Portability: SAS/C extension


SYNOPSIS
DESCRIPTION
RETURN VALUE
IMPLEMENTATION
EXAMPLE
RELATED FUNCTIONS
SEE ALSO


SYNOPSIS

#include <lcstring.h>

int memcmpp (const void *arg1, const void *arg2,
             size_t size1, size_t size2, int pad);


DESCRIPTION

memcmpp compares two arrays ( arg1 and arg2 ), each of which has an associated size ( size1 and size2 ). The shorter array is treated as if it has the same size as the larger, and all additional bytes have the value specified by pad .


RETURN VALUE

memcmpp returns 0 if the two strings are equal, an integer less than 0 if the first string is less than the second, or an integer greater than 0 if the first string is greater than the second.


IMPLEMENTATION

The compiler generates inline code for memcmpp unless memcmpp is undefined (by an #undef statement) to prevent this. The inline code may still call a library routine in special cases (for example, if the length is a variable whose value is larger than 16 megabytes).

Usually, the code generated by memcmpp uses the CLCL instruction to perform the comparison. If more than 16 megabytes of data are to be compared, the library routine is called, which processes 16M-1 bytes at a time.


EXAMPLE

#include <lcstring.h>
#include <stdlib.h>
#include <stdio.h>

#define MAXLEN 100

main()
{
   char line[MAXLEN];
   char *cmdname;
   int cmdlen;

   command:
   puts("enter command:");
   cmdname = gets(line);
   cmdlen = strlen(cmdname);
      /* If the value in cmdname is "exit", possibly       */
      /* followed by trailing blanks, terminate execution. */
   if (memcmpp(cmdname, "exit", cmdlen, 4, ' ') == 0){
      puts("You have asked to exit program; exiting ...");
      exit(0);
   }
   else{
      puts("Command not understood ... try again.");
      goto command;
   }
}


RELATED FUNCTIONS

memcmp


SEE ALSO


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.