This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC 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: [C, C++] fundamental type object representation


Ian Lance Taylor <ian@airs.com> writes:

| Gabriel Dos Reis <gdr@integrable-solutions.net> writes:
| 
| >   Does GCC support any target where the object representation of a
| > fundamental type T (e.g. int, float, double, pointers) whose all bits
| > are zero does not hold value (T)0?
| 
| Surprisingly, the answer seems to be yes. 

Oh gosh.

| For the C4X target, a
| single precision floating point zero is apparently represented as
| 0x80000000 (for double precision there is another 32 zero bits).

Very interesting.

| That said, it doesn't actually work correctly.  Compiling
| 
| float f;
| float g = 0.0;
| struct s { int i; float f; int j; };
| struct s sv = { 1, 0.0, 2 };
| 
| gives me
| 
| 	.file	"foo.c"
| 	.version	40
| 
| 	.data
| data_sec:
| 	.global	_g
| 	.globl	_g
| 	.bss	_g,1
| 	.global	_sv
| 	.data
| _sv:
| 	.word	1
| 	.word	-2147483648
| 	.word	2
| 	.globl	_f
| 	.bss	_f,1
| 	.end
| 
| In other words, the floating point zero is only generated correctly
| when gcc is forced to output the initializer for some other reason.

I guess, this is not something C4X maintainers will correct in the future?

| Given that doesn't work, it is probably reasonably safe to assume gcc
| is always going to generate all zero bits for a fundamental types
| initialized to zero.

OK, thanks.  I was rewriting part of valarray and I saw I made that
assumption, and since it is bug chasing time I thought I should make
sure my use of memset() isn't going to bomb out.

-- Gaby


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