Timeline for How does integer comparison work internally?
Current License: CC BY-SA 3.0
16 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Aug 8, 2017 at 19:49 | comment | added | Ron Klein | I suggest you also take a look at stackoverflow.com/q/4516474/17772 | |
Aug 7, 2017 at 6:08 | comment | added | user1643723 |
@Snowman "which also answers your question", — which question? I am not asking anything… Personally I feel slightly dissatisfied, that the top answer completely ignores higher-level details. The question is tagged with c , but the answer by @John Wu skips "language" part and immediately jumps to circuits-level details. Btw, I am not sure, why people are so eager to close this question as dupe — isn't the supposed dupe target already closed as "too broad"? At least this one is potentially answerable.
|
|
Aug 6, 2017 at 21:57 | comment | added | user22815 | @user1643723 The question is asking about how a computer performs a basic operation, and the top answer discusses logic gates and logic tables. Two topics which are covered extensively in the dupe target's top answer, which also answers your question. | |
Aug 6, 2017 at 5:17 | comment | added | cat |
At compile time, it is constant folded into the constant true , and the if is optimised out completely. This way, your computer never needs to compare numbers! Comparing numbers is hard :(
|
|
Aug 6, 2017 at 2:19 | vote | accept | Niek | ||
Aug 6, 2017 at 0:44 | comment | added | MCMastery | @SJuan76 Actually, at the bottom of the top rated answer (John Wu's answer), it does say it will be compiled to that | |
Aug 5, 2017 at 19:58 | comment | added | user1643723 | @chrylis There is more to integer comparison than just "opcodes" and "logical gates". For example, the signed vs unsigned integer issues have not yet been touched by answers at all. I like that question and it's answers, but being as general as they are, they are doomed to leave a lot of problem-specific details uncovered. | |
Aug 5, 2017 at 19:52 | comment | added | chrylis -cautiouslyoptimistic- | @user1643723 It does when the function in question is a specific opcode. | |
Aug 5, 2017 at 19:34 | comment | added | user1643723 | @Snowman I disagree. Any "how does this work" programming inquiry can be condensed down to that question, but that does not make them duplicates. | |
Aug 5, 2017 at 19:01 | review | Close votes | |||
Aug 13, 2017 at 1:03 | |||||
Aug 5, 2017 at 18:41 | comment | added | user22815 | Possible duplicate of How Do Computers Work? | |
Aug 5, 2017 at 11:36 | history | tweeted | twitter.com/StackSoftEng/status/893797808356175872 | ||
Aug 5, 2017 at 10:49 | comment | added | SJuan76 |
The current answer are ok for the case when the comparation is about variable expression, but lack a disclaimer that many modern compilers will look at your piece of code, detect that the expression will always be true (because of literals) and just ignore the if altogether, going straight to coding do something .
|
|
Aug 5, 2017 at 2:30 | answer | added | John Wu | timeline score: 61 | |
Aug 5, 2017 at 2:14 | review | First posts | |||
Aug 5, 2017 at 8:16 | |||||
Aug 5, 2017 at 2:10 | history | asked | Niek | CC BY-SA 3.0 |