This is the mail archive of the newlib@sources.redhat.com 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]

h8300-elf: Incorrect value of UINT_MAX for -mh -mint32 target.


Hi,
	Following test case would fail fo mint32 targets since the 
	value of UINT_MAX is 65535 where as the size of int is 
	4 bytes. However if the order of included files is 
	reversed then the test case executes correctly.

TEST CASE:
----------------
#include <limits.h>
#include <errno.h>

int main()
{
        unsigned int us = UINT_MAX;

        if (++us == 0)
        {
                printf ("PASSED\n");
        }
        else
        {
                printf ("FAILED\n");
        }

        return 0;
}

PROBLEM:
----------------
The errno.h includes <sys/config.h> which redefine the 
UNIT_MAX as follows:

/* 16 bit integer machines */
#if defined(__Z8001__) || defined(__Z8002__) || defined(__H8300__) ||
defined(__H8500__) || defined(__W65__) || defined (__H8300H__) || defined
(__H8300S__) || defined (__mn10200__) || defined (__AVR__)

#undef INT_MAX
#undef UINT_MAX
#define INT_MAX 32767
#define UINT_MAX 65535
#endif

This does not take care of H8300S and H8300H 32 bit targets.

FIX:
----
Instead of absoule values for INT_MAX and UINT_MAX, the macro
__INT_MAX__ should be used for H8300 targets. The value of 
__INT_MAX__ is appropriately defined in spec.

PATCH:
----------
Index: src/newlib/libc/include/sys/config.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/sys/config.h,v
retrieving revision 1.34
diff -c -3 -p -r1.34 config.h
*** src/newlib/libc/include/sys/config.h        11 Oct 2002 10:28:30 -0000
1.34
--- src/newlib/libc/include/sys/config.h        13 Dec 2002 15:02:41 -0000
***************
*** 20,25 ****
--- 20,35 ----
  #define UINT_MAX 65535
  #endif

+ #if defined (__H8300H__) || defined(__H8300S__)
+ #if defined (__INT_MAX__)
+ #undef INT_MAX
+ #undef UINT_MAX
+ #define INT_MAX __INT_MAX__
+ #define UINT_MAX (__INT_MAX__ * 2U + 1)
+ #endif
+ #endif
+
+
  #ifdef __W65__
  #define __SMALL_BITFIELDS
  #endif

Thanks and Regards,
Nitin


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