This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: h8300, m32c and PRIuPTR



On 3/16/2015 10:08 AM, Corinna Vinschen wrote:
> On Mar 16 09:38, Joel Sherrill wrote:
>>
>> On 3/16/2015 9:10 AM, Eric Blake wrote:
>>> On 03/16/2015 04:22 AM, Nicholas Clifton wrote:
>>>> Hi Joel,
>>>>
>>>>> The warning is:
>>>>>
>>>>> f.c:6:3: warning: format '%u' expects argument of type 'unsigned int',
>>>>> but argument 2 has type 'uintptr_t' [-Wformat=]
>>>>>     printf( "%" PRIuPTR "\n", x );
>>>>> Any ideas on how to address this?
>>>> How about using an explicit widening cast, as in:
>>>>
>>>>       printf ("%lu\n", (unsigned long) x);
>>>>
>>>>
>>>> I am assuming that sizeof (uintptr_t) <= sizeof (unsigned long) will
>>>> always be true, but that seems reasonable to me.
>>> Not on 64-bit mingw (where sizeof(long)==4, sizeof(uintptr_t)==8).  But
>>> yes, explicitly widening to a known type can work around cases where you
>>> are otherwise stumped, although for this particular code, it looks like
>>> PRIuPTR is misdefined for your platform.
>>>
>> And we don't want to add casts. We just want to use the PRIxxx constants
>> to have portable printf formats and avoid warnings.
>>
>> I am wondering if when we avoided changing newlib-stdint.h to match the
>> logic
>> in glibc-stdint.h for uintptr_t by adding configure time logic, we just
>> pushed
>> off the problem. At this point, all I can see as a solution is something
>> like this
>> in inttypes.h:
>>
>> #if defined(__m32c__) || defined(__h8300__)
>>   /* do whatever is needed */
>> #else
>>   /* we can rely on the value provided by configure, use current logic */
>> #endif
> Did you see my mail mentioning sys/config.h?
This one?
> Ideally the setting is available via compile time macros and can be used
> to set _UINTPTR_EQ_ULONG or _UINTPTR_EQ_ULONGLONG from include/sys/config.h.
So remove the configure.in logic and try to do the same thing dynamically
with conditionals based on __SIZEOF_PTRDIFF__ and __SIZEOF_LONG_LONG__,
__SIZEOF_LONG__, and __SIZEOF_INT__?

This will work in some cases but with sizeof(int) == sizeof(long),
newlib-stdint.h
is inconsistent whether uintptr_t is "unsigned int" or "long unsigned
int". 
And that was the more easily hit inttypes.h problem that added the logic
to configure.in.
> Again, the size of pointer values as well as the fact what multilib
> we're building for should be available from gcc at compile time.  This
> information should ideally be used to influence the logic of inttypes.h
> in sys/config.h.
>
Can we reliably determine long or int for uintptr_t with cpp conditionals?
> Corinna
>

-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel.sherrill@OARcorp.com        On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
Support Available                (256) 722-9985



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]