LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-29-2009, 10:32 PM   #1
figo
LQ Newbie
 
Registered: May 2009
Posts: 14

Rep: Reputation: 0
Smile interesting integer type comparison problem


Hi, I have curious question when reviewing C in terms of integer type comparison.

What happens when

int a;
long int b;
double c;
...

if (a>b) { <----?
.....
} else
if (a<c) { <----?
...
}

I know conversion rules for integer and so on. But I think they only apply for arithmetic operation. I assume > < operator will be different. But can't imagine the details.. maybe sth like
1> variable a hoist to long int to match with b's type
2> compare a and b by substracting (at assembly level cmp)

The underlying question is that will truncation or undefined behavior happen..

Your thoughts are highly appreciated.
 
Old 09-29-2009, 10:33 PM   #2
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
the compiler auto converts them to a common type
 
Old 09-29-2009, 10:35 PM   #3
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
uaualy it converts the bit width of the small one to the bit width of the large one
like if you have a 16 and 32 bit numbers it will widen the 16 bit number
to 32 so it can compare them
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ISO C++ forbids comparison between pointer and integer BarryKamp Programming 5 04-25-2007 09:06 PM
comparison between pointer and integer a problem? debiant Programming 7 08-28-2006 07:57 PM
Comparison between pointer and integer ---> WHY?? its_godzilla Programming 10 01-28-2005 09:40 PM
ISO C++ forbids comparison between pointer and integer? pimaster Programming 1 11-06-2003 01:45 PM
C programming error. warning: comparison between pointer and integer Linh Programming 4 06-06-2003 03:49 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration