Demoting Integral Values

Jun 6, 2011 at 2:53am
So I was looking at windows api today and I see this macro:
 
#define LOWORD(w) ((WORD) (w)) 

Analogously,
1
2
3
4
5
6
7
8
#include <stdio.h>

int main(int argc, const char* argv[]) {
    long long l = 4544444444LL;
    int s = l;
    printf("%d", s);
    return 0;
}


But I thought the behavior was undefined for this sort of demotion. I.e. that demotions always throw away high order bits is not true in general. I know the standards are defined somewhere, if you needed to know this, how would you look it up? (no random googling)
Jun 6, 2011 at 8:26am
I.e. that demotions always throw away high order bits is not true in general.
I don't think you're right about that.. In what case does throwing away bits not work?
Assembly doesn't seem to have a type conversion function downwards, so I assume it is trivial. (See http://flatassembler.net/docs.php?article=manual#2.1.2 )
Jun 6, 2011 at 2:45pm
I was playing devil's advocate. Is there some standard reference in which I can look up the answer to these sorts of language questions?
Last edited on Jun 6, 2011 at 2:46pm
Jun 6, 2011 at 4:47pm
Well, you could look at C++ language standard. About this it says
If the destination type is unsigned, the resulting value is the least unsigned integer congruent to the source
integer (modulo 2n where n is the number of bits used to represent the unsigned type). [Note: In a two’s
complement representation, this conversion is conceptual and there is no change in the bit pattern (if there
is no truncation). ]

Or you can always simply ask here..
Topic archived. No new replies allowed.