Re: An example of MACHO programming and why is wrong
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Mon, 01 Jan 2007 10:57:58 -0500
jacob navia wrote:
.... snip ...
Suppose:
struct S {
unsigned n;
double d;
double data[8192];
};
I want to allocate 65520 objects of size 65 552 bytes each.
If you do that in a 32 bit system what you obtain?
i=65520, i*sizeof(*p)=4,294,967,040 as signed number = -256
WE OBTAIN A NEGATIVE NUMBER.
Very simple. We detect the 'unsigned overflow' by:
if (((n = a * b) < a || (n < b)) overflow()
else alliswell(n);
--
Merry Christmas, Happy Hanukah, Happy New Year
Joyeux Noel, Bonne Annee.
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
.
- Follow-Ups:
- Re: An example of MACHO programming and why is wrong
- From: Keith Thompson
- Re: An example of MACHO programming and why is wrong
- From: Peter Nilsson
- Re: An example of MACHO programming and why is wrong
- References:
- Re: size_t or int for malloc-type functions?
- From: Richard Heathfield
- Re: size_t or int for malloc-type functions?
- From: jacob navia
- Re: size_t or int for malloc-type functions?
- From: Richard Heathfield
- Re: size_t or int for malloc-type functions?
- From: Richard Tobin
- Re: size_t or int for malloc-type functions?
- From: Richard Heathfield
- An example of MACHO programming and why is wrong
- From: jacob navia
- Re: size_t or int for malloc-type functions?
- Prev by Date: Re: CSQA & CSTE Prep Courses for International Certifications by QAI,USA
- Next by Date: Is IPC in standard C possible?
- Previous by thread: Re: An example of MACHO programming and why is wrong
- Next by thread: Re: An example of MACHO programming and why is wrong
- Index(es):
Relevant Pages
|