RTEMS printk fails for large unsigned integers

Ralf Corsepius ralf.corsepius at rtems.org
Wed Dec 2 09:01:35 UTC 2009


On 11/27/2009 05:36 PM, Joris van Rantwijk wrote:
>
> On 27 nov 2009, at 16:44, Ralf Corsepius wrote:
>>> I noticed that printk("%u", x) prints "0" for values of x larger than
>>> LONG_MAX.
>> Which target/BSP? printk is target/BSP specific.
>
> No. This part of printk is implemented in cpukit/libcsupport/src/vprintk.c
> The target in this case is sparc/leon3.
>
>> Furthermore, printing variable greater LONG_MAX with "%u" formating is
>> invalid/non-portable code.
>
> What would be the purpose of "%u" in that case?
%u is limited to "int"s

For longs, the "l" modifier must be applied.

The fact that longs and ints happen to be identical on some targets, and 
the fact that sizes of ints, longs and pointers also happen to be 
identical on some targets is a mere random coincidence.

It's non-portable and breaks ad-lib in many situation.

> Where is the documentation for printk that declares this use to be invalid?
I am referring to printf's documentation as specified by POSIX/IEEE 
standards, not to RTEMS proprietary and largely undocumented 
reimplementation called printk[1]

Ralf

[1] I consider existence of printk in RTEMS to be a design flaw. It's 
appropriate for usage in (kernel-space) situations, where printf's 
infrastructure is not ready yet or is not applicable, but I encourage 
everybody not to use it outside of the actual kernel.



More information about the users mailing list