[Flac-dev] need help with MSVC

Erik de Castro Lopo erikd-flac at mega-nerd.com
Sat Feb 3 21:41:52 PST 2007


Josh Coalson wrote:

> for recent code changes I find myself needing some workarounds
> for MSVC6:

Yep. MSVC is borked. Its missing most of the new maths functions that
were introduced in the C99 standard.

The way I solved this problem for libsndfile was to stop using MSVC,
(allowing it to break for that compiler) and use MinGW. I also
release a pre-compiled win32 binary so (theorectically) noone can 
bitch about libsndfile not compiling.

The downside of this is that there is no way to compile libsndfile
for win64 until MinGW gets updated for that platform.

> 1st, I need a fast way to swap bytes (for endianness) of a 32-bit
> int.  I could not find a builtin like bswap;

If you really want to continue supporting MSVC I suggest you write
a C header file containing inline functions with win32/MSVC asm
statements that replicate the functionality of linux's <endian.h>.

If you name the win32 replacements the same as the linux versions
it should just work on both platforms.

> the closest thing I found was ntohl() which appears to be a 
> function call

Avoid that like the plague.

> 2nd, I need an equivalent for lround() (or round() is ok), which
> is not in MSVC6's math.h or anywhere else I could find.

The operation of lround() is basically the same as lrint(). In
src/float_cast.h I have:

	__inline long int
	lrint (double flt)
	{	int intgr ;

		_asm
		{	fld flt
			fistp intgr
			} ;

		return intgr ;
	}

	__inline long int
	lrintf (float flt)
	{	int intgr ;

		_asm
		{	fld flt
			fistp intgr
			} ;

		return intgr ;
	}



Hope this helps,
Erik
-- 
+-----------------------------------------------------------+
  Erik de Castro Lopo
+-----------------------------------------------------------+
The National Multiple Sclerosis Society of America recently started an
advertising campaign with the slogan "MS: It's not a software company".

Seasoned IT professionals will have no trouble telling the two MS's
apart. One is a debilitating and surprisingly widespread affliction
that renders the sufferer barely able to perform the simplest task.
The other is a disease.


More information about the Flac-dev mailing list