Keil™, An ARM® Company

Technical Support

C166: USING XHUGE POINTERS WITH LIBRARY ROUTINES LIKE STRCPY


Information in this article applies to:

  • C166 All Versions

SYMPTOMS

I have a lot of data structures that are larger than 64K. They are declared with the xhuge memory type. I'm using strcpy to copy data and the copy doesn't seem to work correctly. I'm using the HLARGE memory model. Are there any known problems with doing this?

CAUSE

The problem you are having is a result of the assumed data type in the HLARGE memory mode. In HLARGE, variables are huge by default. The strcpy library routine (as well as many others) use standard types, for example:

char *strcpy (char *d, char *s);

The pointers you pass to strcpy are assumed to be pointers to huge variables and not pointers to xhuge variables.

RESOLUTION

A number of library routines have xhuge equivalents. For example:

  • xcalloc is the xhuge equivalent of calloc.
  • xfree is the xhuge equivalent of free.
  • xinit_mempool is the xhuge equivalent of init_mempool.
  • xmalloc is the xhuge equivalent of malloc.
  • xmemcmp is the xhuge equivalent of memcmp.
  • xmemcpy is the xhuge equivalent of memcpy.
  • xmemmove is the xhuge equivalent of memmove.
  • xmemset is the xhuge equivalent of memset.
  • xrealloc is the xhuge equivalent of realloc.

For those functions that do not have xhuge equivalents, you must write your own. The following example shows how to write the strcpy library routine for xhuge variables.

char xhuge *xstrcpy (
  char xhuge *d,
  char xhuge *s)
{
char xhuge *r;

for (r = d; (*d = *s) != '\0'; s++, d++);

return (r);
}

MORE INFORMATION

Last Reviewed: Friday, July 15, 2005