cleaner & greener (was Re: A patch for RTEMS4.10.0 PowerPC heap space initialization)

Peter Dufault dufault at
Thu May 12 11:10:47 UTC 2011

On May 12, 2011, at 6:10 , Sebastian Huber wrote:

> No, uintptr_t is the type used by the heap code.  We work here with addresses
> and not sizes of single objects.

I had to look up the definition of uintptr_t.  At least according to Wikipedia it's C99 and is defined as:

Integers wide enough to hold pointers
intptr_t and uintptr_t is a signed and unsigned integer which are guaranteed to hold the value of a pointer. These two types are optional.

"The limits of these types are defined with the following macros:

	• INTPTR_MIN is the minimum value (−32,767 [−215 + 1] or less) of intptr_t.
	• INTPTR_MAX is the maximum value (32,767 [215 − 1] or greater) of intptr_t.
	• UINTPTR_MAX is the maximum value (65,535 [216 − 1] or greater) of uintptr_t.

Here's the function:

    void       **work_area_begin,
    uintptr_t   *work_area_size,
    void       **heap_begin,
    uintptr_t   *heap_size,
    uintptr_t   *sbrk_amount);

Without looking at the code it appears that "work_area_begin" is referring to an address, but that's pointing to a "void *" and not a "uintptr_t".  "work_area_size" sure sounds as if it is returning a size and not an address.

I don't see much benefit of uintptr_t over void * at the moment, I'll have to try to think of one.  I'd expect the signature to be:

    void       **work_area_begin,
    size_t      *work_area_size,
    void       **heap_begin,
    size_t      *heap_size,
    size_t      *sbrk_amount);

Or, to provide abstraction without stepping on the "_t" restricted name space,

    address_type       *work_area_begin,
    address_size_type  *work_area_size,
    address_type       *heap_begin,
    address_size_type  *heap_size,
    address_size_type  *sbrk_amount);

1. When would address_type not be void *?
2. When would address_size_type not be size_t?

Peter Dufault
HD Associates, Inc.      Software and System Engineering

More information about the users mailing list