Keil Logo

C166: SPRINTF AND FAR STRINGS


Information in this article applies to:

  • C166 All Versions

QUESTION

In C166, I'm using sprintf to get formatted data into a far array of characters. My question is: Is it valid to pass strings that exist in far memory to sprintf as shown here?

#define achBuffer XARRAY ( char, 0x100000 )
sprintf( achBuffer, "%d", 1 );

If yes, which memory models (other than TINY) is it not valid for?

ANSWER

Yes. This is valid. In the C166, the following memory models, by default, assume that variables are of the indicated types.

Memory Model      Variable Memory
---------------------------------
TINY              near
SMALL             near
COMPACT           far
HCOMPACT          huge
MEDIUM            near
LARGE             far
HLARGE            huge
---------------------------------

In COMPACT and LARGE memory models, sprintf assumes that the buffer is in far memory (and a far pointer is needed).

Since a far pointer can be converted into a huge pointer, HCOMPACT and HLARGE models will also work for your example (because far pointers can be converted into huge pointers).

MEDIUM, SMALL, and TINY models will not work (unless you luck out and the far memory is in the same space as the near memory).

MORE INFORMATION

Last Reviewed: Friday, July 15, 2005


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.