arithmetic conversion

F

Fraser Ross

int A(int size){
if (size < (unsigned int)0)
return 1;

return 0;
}


If I pass for instance -10 to A should I not have 0 returned? The type
int should be converted to unsigned int and -10 will be some large
number with a 2's complement arithmetic processor.

Fraser.
 
V

Victor Bazarov

Fraser said:
int A(int size){
if (size < (unsigned int)0)
return 1;

return 0;
}


If I pass for instance -10 to A should I not have 0 returned? The
type int should be converted to unsigned int and -10 will be some
large number with a 2's complement arithmetic processor.

It doesn't matter whether your processor is 2's complement or not.
-10 converted to unsigned is definitely greater than 0, so the '<'
yields false and 'return 1' should be skipped.

What are you getting and with what compiler?

V
 
F

Fraser Ross

What are you getting and with what compiler?

Borland C++ Builder 2006 gives 1.

Fraser.
 
M

Matthias Buelow

Fraser said:
Borland C++ Builder 2006 gives 1.

I know next to nothing about Borland C++ Builder but I've recently been
porting some code to g++ that was written with it and I can say that
Borland seems to accept a language that has only a superficial
resemblance to C++. Maybe there's some switch or something that kicks it
in to Standard C++ mode, if so, you should try again with that mode
enabled. Otherwise, the Borland compiler appears not to be a good
reference for checking what is legal behaviour in C++.
 
F

Fraser Ross

"Matthias Buelow"
enabled. Otherwise, the Borland compiler appears not to be a good
reference for checking what is legal behaviour in C++.

Theres quite a good effort now from CodeGear to fix bugs. The last
couple of compilers have had many bugs fixed.

Fraser.
 

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

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,967
Members
47,517
Latest member
Andres38A1

Latest Threads

Top