for recent code changes I find myself needing some workarounds for MSVC6: 1st, I need a fast way to swap bytes (for endianness) of a 32-bit int. I could not find a builtin like bswap; the closest thing I found was ntohl() which appears to be a function call and also requires linking with winsock2 (ws2_32.lib) to get it. 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. TIA, Josh ____________________________________________________________________________________ Cheap talk? Check out Yahoo! Messenger's low PC-to-Phone call rates. http://voice.yahoo.com
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 callAvoid 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.
Josh Coalson wrote:> 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.I've just updated from CVS and noticed that you are using lround() but when I compile I get: lpc.c: In function 'FLAC__lpc_quantize_coefficients': lpc.c:205: warning: implicit declaration of function 'lround' lpc.c:205: warning: incompatible implicit declaration of built-in function 'lround' lpc.c:240: warning: incompatible implicit declaration of built-in function 'lround' The lround funtion is part of C99 and to enable it with gcc you need -std=c99 or -std=gnu99 on the as part of the gcc commandline. Hope this helps, Erik -- +-----------------------------------------------------------+ Erik de Castro Lopo +-----------------------------------------------------------+ "There is no satisfactory substitute for excellence." -- Dr. Arnold O. Beckman
--- Erik de Castro Lopo <erikd-flac@mega-nerd.com> wrote:> Josh Coalson wrote: > > the closest thing I found was ntohl() which appears to be a > > function call > > Avoid that like the plague.why so? on linux/glibc it appears to map to just a nop or bswap builtin. Josh ____________________________________________________________________________________ Have a burning question? Go to www.Answers.yahoo.com and get answers from real people who know.
Possibly Parallel Threads
- need help with MSVC
- Cross-compiling libc++ to linux-armv7hf gives undefined symbols in cmath / math.h
- Why R order files as 1 10 100 not 1 2 3 ?
- [PATCH 2/2] Update and improve autotools build
- [LLVMdev] [Polly] Performance comparison between Cloog and ISL code generation