Keil Logo

C51: PROBLEMS USING PRINTF


Information in this article applies to:

  • C51 All Versions

QUESTION

I can get the printf command to work with integers but not long integers or 8-bit integers. Why?

ANSWER

You must use the optional characters B or b and L or l immediately preceding the type character to respectively specify char or long versions of the integer types d, i ,u, o, x and X.

The following printf correctly prints 1, 2, and 3 as integers:

printf ("%d %d %d", (int) 1, (int) 2, (int) 3);

The following printf correctly prints 1, 2, and 3 as long integers:

printf ("%Ld %Ld %Ld", 1L, 2L, 3L);

The following printf correctly prints 1, 2, and 3 as chars:

printf ("%Bd %Bd %Bd", (char) 1, (char) 2, (char) 3);

The type casts on the numeric constants are important because they specify the number of bytes required for each numeric constant.

FORUM THREADS

The following Discussion Forum threads may provide information related to this topic.

Last Reviewed: Wednesday, May 5, 2004


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.