Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FFMPEG compilation without compiler optimization

Tags:

c

ffmpeg

I'm compiling ffmpeg for win32 using Microsoft cl compiler. I need to compile it without any optimization, so added configure --extra-cflags= -Od".

Compilation goes fine, but there are a few places like this:

Last 3 ifs.

The code compiles, but doesn't link because calls like ff_sbrdsp_init_arm(s); are not removed by compiler. Of course everything is fine when compiling with optimization. Then compiler removes all if(0)s.

There are several similar places in ffmpeg. Why if(0) is used instead of preprocessor's #if 0?

Is there any hidden trick behind this?

like image 936
Kamil_H Avatar asked Oct 20 '22 07:10

Kamil_H


1 Answers

One advantage of if (0) C; over the #if or #ifdef solution is that the code is still type-checked by the compiler. If someone changes the prototype of one of the functions invoked within C, the compiler will warn that the callsite needs to be adjusted, even if the person doing the compilation does not use this configuration.

For your practical problem of compiling the code with a compilation platform that does not remove these dead calls, you can safely change them to the preprocessor version(*). However, perhaps you should explain why you must compile without optimizations. Perhaps it would be allowable and possible to enable just the optimization that removes this kind of dead code.

(*) Here I subtly avoided to specifically recommend either #if ARCH_ARM or #ifdef ARCH_ARM, but this is doing you a disservice. Be aware that they are different. If ARCH_ARM is always defined as either 0 or 1, use #if ARCH_ARM. If it is either defined or not, use #ifdef. If the macro is intended to work inside if (…), it is the former case.

like image 152
Pascal Cuoq Avatar answered Oct 27 '22 10:10

Pascal Cuoq