Keil Logo

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 1

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);
}

RESOLUTION 2

A new memory model called XLarge has been introduced which uses xhuge pointer by default. The appropriate library functions will then be used automatically. This can be used since the C166 version 7.04.

MORE INFORMATION

Last Reviewed: Monday, November 7, 2011


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.