NVIDIA Interview Question
Software Engineer / DevelopersRight, I understand that. But does this answer the question? I think he asked for something like casting. I.e. if we add signed and unsigned numbers, which will be cast to which?
6.3.1.3 Signed and unsigned integers.
I think i found it. You made me look, but this is a 2007 draft of C99. I still cannot find the grammar.
1 When a value with integer type is converted to another integer type other than _Bool, if the value can be represented by the new type, it is unchanged.
2 Otherwise, if the new type is unsigned, the value is converted by repeatedly adding or subtracting one more than the maximum value that can be represented in the new type until the value is in the range of the new type.49)
3 Otherwise, the new type is signed and the value cannot be represented in it; either the result is implementation-defined or an implementation-defined signal is raised.
Signed integer max 2^31, Unsigned 2^32. You are asking for trouble if unsigned number is big.
- Anonymous February 26, 2011