[GRASS-dev] trouble compiling v.in.ogr + math.h (all branches)

Glynn Clements glynn at gclements.plus.com
Mon Jun 10 06:11:28 PDT 2013


Hamish wrote:

> when I try to compile a fresh check out of 6.4.3svn on an older
> system (glibc 2.3.6) I get this error from v.in.ogr:
> 
> main.c: In function 'main':
> main.c:1208: error: implicit declaration of function 'log2'
> main.c:1208: warning: incompatible implicit declaration of built-in function 'log2'
> 
> 
> I thought it was because #include <math.h> was missing (for pow()
> and log10() too), but after adding that I still get the error.
> 
> It turns out I need to add -std=c99 to the gcc line to get it
> to work, but the glibc man page for log2() has it conforming to
> SVr4, 4.3BSD, C89.

Huh? On my system, the log2 manual page says:

	CONFORMING TO
	       C99, POSIX.1-2001. The variant returning double also conforms
	       to SVr4, 4.3BSD.

> maybe I could replace it with a log()/log() trick, but would
> pow() and log10() also be broken?

pow() and log10() are C89. As is exp2(), FWIW.

But if you're planning on replacing this:

	new_snap = log2(xmax) - 52;
	new_snap = pow(2, new_snap);

I'd suggest using:

	int exp;
	new_snap = frexp(xmax, &exp);
	exp -= 52;
	new_snap = ldexp(new_snap, exp);

frexp() and ldexp() are C89, don't introduce rounding errors, and
handle zero correctly (they're also likely to be more efficient, but
that's a trivial detail).

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


More information about the grass-dev mailing list