defining typed constant numbers in C/C++
问题 In C/C++, is there a difference between saying (1U) vs. ((unsigned int)1) ? I prefer the second one, but I am concerned that the second one may be type-cast at run time (i.e. extra cpu cycles), whereas the first one gets the correct type at compilation. Thanks. 回答1: They're not equivalent. 1U is valid in #if preprocessing directives. (unsigned int)1 is a syntax error at the preprocessor level. You could however make it (unsigned)+1 and it would be valid in the preprocessor, but only because