Dear all,

Is it really intended that ptrdiff_t is 32bit?
I guess not, because the "gcc47: 20-Bit Design" states:
"Memory model target options are accepted only when building for
CPUX-capable MCUs. Compilation for non-CPUX MCUs effectively uses the
small memory model."
And before that about the small memory model was stated:
"size_t and ptrdiff_t are 16 bits, and no data object may exceed 32767 bytes."

I am referring to mspgcc-20120406-p20120502 (non-CPUX)

For a quick check how msp430-gcc is configured:
$ msp430-gcc -dM -E - < /dev/null | grep PTRDIFF
#define __PTRDIFF_MAX__ 2147483647L
#define __SIZEOF_PTRDIFF_T__ 4
#define __PTRDIFF_TYPE__ long int

In contrast to the AVR gcc:
$ avr-gcc -dM -E - < /dev/null | grep PTRDIFF
#define __PTRDIFF_MAX__ 32767
#define __SIZEOF_PTRDIFF_T__ 2
#define __PTRDIFF_TYPE__ int

I came across this issue when looking at the generated code for int
pointer subtraction. Surprisingly huge code, because a sign extension
and a 32bit subtraction was performed.
However when dealing with a char pointers subtraction (being casted
into an int result) the 32bit operations are optimized away. That
might explain why this has not been noticed yet.

Regards,
Guido

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Mspgcc-users mailing list
Mspgcc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mspgcc-users

Reply via email to