[geeks] Quick C question

Joshua D Boyd jdboyd at cs.millersville.edu
Wed Jul 24 23:10:19 CDT 2002


On Wed, Jul 24, 2002 at 11:02:37PM -0500, Jonathan C. Patschke wrote:
 
> The problem is that 2891336453 won't fit in 31 bits, so the compiler is
> telling you that it inferred a type based on its content, and that type
> might not be what you intended.
> 
> To tell it that you're okay with that constant being an unsigned int (as
> opposed to the assumed default of int), append a U to the end of the
> constant, like this:
> 
> s = s * 2891336453U + 1;

I got what the problem was, just didn't know about sticking a U at the
end of the number.
 
> It's also a warning that your multiply and add will probably result in
> overflow (if s is an int) or loss of significant digits (if s is a float).

I didn't give any context for where is was appearing, but since it is
a random number generator, I'd imagine overflows are the idea.
 
> Also, just as a matter of style, 2891336453 is a magic number.  That is,
> it doesn't mean anything out of context.  Consider making a symbolic
> #define for that constant that would make that calculation more
> meaningful.

The random number generator files of the code I'm working over are
full of magic numbers, that I don't really have names for, or really
know what exactly they are doing.  I think I'll avoid naming them for
now for that reason.

-- 
Joshua D. Boyd



More information about the geeks mailing list