[GRASS-dev] is this compiler-safe?

Glynn Clements glynn at gclements.plus.com
Wed Feb 10 19:29:23 EST 2010


Markus Metz wrote:

> Any suggestions on how to compute required file size on 32bit OS with 
> sizeof(off_t) = 4 ?
> e.g.
> (double) nrows * ncols * sizeof(DCELL)
> or
> (long long int) nrows * ncols * sizeof(DCELL)
> more generic
> number_of_items * sizeof(item)
> 
> and safely compare that to 2^31 (2GB)?

Use double, cast to off_t, check that the two are equal, e.g.

	double d_size = (double) nrows * ncols * sizeof(DCELL);
	off_t size = (off_t) d_size;

	if ((double) size != d_size)
	    G_fatal_error(_("File too large"));

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-dev mailing list