"Condition is Always False" Question

G

Grizlyk

Victor said:
'unsigned int' and 'int' are required to have the same size. The
requirement is that a negative int 'a' when converted to unsigned
int produces (2^n + a) (where 'n' is the size in bits of the types).
Defining UINT_MAX as _different from_ (2^n - 1) is not possible if
we intend to satisfy the requirement that unsigned types behave the
way 3.9.1/4 requires ("obey the laws of arithmetic modulo 2^n").
negative int 'a' when converted to unsigned int produces (2^n + a)
Do not understand the expression, but do not insist.


C++ have a kind of "virtual machine" for memory layout. There are systems,
that contains not-crossing memory banks for each size of memory data, placed
by the same address, for example, memory layout

{
//CHAR_BITS is 8
char *c=(char*)0x1000;

//sizeof(int) is 2
int *i=(int*)0x1000;

//sizeof(long) is 4
long *g=(long*)0x1000;

//total_memory_size in chars
//long memory[(total_memory_size/4)/3][3]

//memory banks dump
*c=1; //{0x00000001,0x00000000,0x00000000}
*i=2; //{0x00000001,0x00000002,0x00000000}
*g=3; //{0x00000001,0x00000002,0x00000003}

++c;
*c=1; //{0x00000101,0x00000002,0x00000003}
++i;
*i=2; //{0x00000101,0x00020002,0x00000003}
}

is not supported for C++ directly, because each banks is not accessable as
chars and C++ compiler, hosted on the system, must implement special
convertions to touch and use all banks of memory if it is main operational
memory.

Probably, by analogy with memory, C++ signed is also can be "virtualized"
and for CPU with "-1" represented as "0xfffe", C++ will convert "-1" to
"0xffff"

{
int i=-1; //memory hold "0xfffe"
printf("%d\n",i);
//call _i2i //"0xfffe" -> "0xffff"
//call _printf //_printf expect "0xffff" as "-1"

unsigned u=(unsigned)i;
//call _i2u "0xfffe" -> "0xffff"

++i;
//CPU harware makes i=0x0000
}
 
P

Pete Becker

Grizlyk said:
On x86 CPU yes, but it seems to me, that C++ does not require that MSB is
always sign bit, so representaion of "-1" in theory can be any (not only in
complementary binary code, where "-a == (~a)+1" , for example "-1" can be
"0xfffe", not "0xffff".

You snipped too much context. The assertion was that assigning -1 to an
unsigned short resulted in the value 65535. That's correct if unsigned
short represents values from 0 to 65535. If it holds a larger range the
result is a larger value, namely, USHORT_MAX. That's independent of how
the values are represented in the hardware.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
 
M

Marcus Kwok

Victor Bazarov said:
C++ supports three representations at this time: 2's complement, 1's
complement and signed magnitude.

I don't doubt you (you have demonstrated that you have much greater
knowledge of the standard than I do), but I am surprised by this. I
would have thought that with C++'s goal of being portable to many
architectures, it would allow for a biased representation[0] for
numbers.

[0] See how the exponent is stored in IEEE 754 floating point format:
http://en.wikipedia.org/wiki/IEEE_754#Exponent_biasing
 
V

Victor Bazarov

Marcus said:
Victor Bazarov said:
C++ supports three representations at this time: 2's complement, 1's
complement and signed magnitude.

I don't doubt you (you have demonstrated that you have much greater
knowledge of the standard than I do), but I am surprised by this. I
would have thought that with C++'s goal of being portable to many
architectures, it would allow for a biased representation[0] for
numbers.

Is there a real architecture that has such representation or is that
just theoretical?
[0] See how the exponent is stored in IEEE 754 floating point format:
http://en.wikipedia.org/wiki/IEEE_754#Exponent_biasing

V
 
R

Rolf Magnus

Marcus said:
Victor Bazarov said:
C++ supports three representations at this time: 2's complement, 1's
complement and signed magnitude.

I don't doubt you (you have demonstrated that you have much greater
knowledge of the standard than I do), but I am surprised by this. I
would have thought that with C++'s goal of being portable to many
architectures, it would allow for a biased representation[0] for
numbers.

It requires that the bit combination for positive integers is the same for
signed and unsigned types.
 
R

Rolf Magnus

Victor said:
Marcus said:
Victor Bazarov said:
C++ supports three representations at this time: 2's complement, 1's
complement and signed magnitude.

I don't doubt you (you have demonstrated that you have much greater
knowledge of the standard than I do), but I am surprised by this. I
would have thought that with C++'s goal of being portable to many
architectures, it would allow for a biased representation[0] for
numbers.

Is there a real architecture that has such representation or is that
just theoretical?

Does that matter?
 
V

Victor Bazarov

Rolf said:
Victor said:
Marcus said:
C++ supports three representations at this time: 2's complement,
1's complement and signed magnitude.

I don't doubt you (you have demonstrated that you have much greater
knowledge of the standard than I do), but I am surprised by this. I
would have thought that with C++'s goal of being portable to many
architectures, it would allow for a biased representation[0] for
numbers.

Is there a real architecture that has such representation or is that
just theoretical?

Does that matter?

Why wouldn't it?
 
K

Kai-Uwe Bux

Rolf said:
Victor said:
Marcus said:
C++ supports three representations at this time: 2's complement, 1's
complement and signed magnitude.

I don't doubt you (you have demonstrated that you have much greater
knowledge of the standard than I do), but I am surprised by this. I
would have thought that with C++'s goal of being portable to many
architectures, it would allow for a biased representation[0] for
numbers.

Is there a real architecture that has such representation or is that
just theoretical?

Does that matter?

Sure: if the question was about concrete architectures, it would be
off-topic. <g>


Best

Kai-Uwe Bux
 
M

Marcus Kwok

Victor Bazarov said:
Marcus said:
Victor Bazarov said:
C++ supports three representations at this time: 2's complement, 1's
complement and signed magnitude.

I don't doubt you (you have demonstrated that you have much greater
knowledge of the standard than I do), but I am surprised by this. I
would have thought that with C++'s goal of being portable to many
architectures, it would allow for a biased representation[0] for
numbers.

Is there a real architecture that has such representation or is that
just theoretical?

The question was just theoretical.
 
M

Marcus Kwok

Rolf Magnus said:
Marcus said:
Victor Bazarov said:
C++ supports three representations at this time: 2's complement, 1's
complement and signed magnitude.

I don't doubt you (you have demonstrated that you have much greater
knowledge of the standard than I do), but I am surprised by this. I
would have thought that with C++'s goal of being portable to many
architectures, it would allow for a biased representation[0] for
numbers.

It requires that the bit combination for positive integers is the same for
signed and unsigned types.

OK, then this would disqualify the biased representation (unless the
bias is 0, which doesn't give you anything usefully different). Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,142
Latest member
arinsharma
Top