ARM Technical Support Knowledge Articles

PROBLEMS USING PRINTF

Applies to: C51 C Compiler

Answer


Information in this article applies to:


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.

Article last edited on: 2004-05-05 20:34:23

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential