Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » jpgalleg fails to build with default C standard (Needs C90)

This thread is locked; no one can reply to it. rss feed Print
jpgalleg fails to build with default C standard (Needs C90)
Edgar Reynaldo
Member #8,592
May 2007
avatar

Hi guys.

TestJpegBuild.zip

I've been having some trouble getting the JpgAlleg addon for Allegro 4.4.3 to build in debug mode. I've narrowed the problem down to it being built with the default C standard (I don't know what that is). It builds fine with -std=c90 though, without warnings, and without linker errors.

So my question is, is Allegro 4.4.3 supposed to be built as C90 code? What is the standard that Allegro is adhering to?

I finally figured it all out by making a test case. The problem is with a function declaration for the get_value function being declared as _inline_ in jpgalleg in decode.c. When building the debug version of jpgalleg there is no standard specified and the linker throws an error saying there is an undefined reference to the inlined function get_value. The only instances of calls to the get_value function appear below its definition in the same source file, so I'm not sure why the linker is looking for an out of line version of get_value.

It must be something to do with the way the default behavior is handled because the problem doesn't appear with GCC 4.8.1. It only started when I tried to compile Allegro 4.4.3 and JpgAlleg with GCC 5.3.0.

I have attached a zip file of the test case. There are two batch scripts for building the test. CompileC90.bat and CompileNoSTD.bat. One compiles as C90 and the other uses the default standard (whatever that is).

You need GCC 5.3.0 to see this behavior. The script uses mingw32-gcc as the c compiler.

As soon as this issue is resolved, I can finish my build of Allegro 4.4.3 and make a release.

I'm more than willing to make a patch for this, but I don't know how to proceed. I'm not sure what the correct way to enforce inlining is, and it depends on the standard being used.

EDIT
I tried to build Allegro 4.4.3 with -std=c90 and it fails at 26% in rotate.c due to C++ style comments

torhu
Member #2,727
September 2002
avatar

The default semantics of inline have changed:
https://gcc.gnu.org/gcc-5/porting_to.html

I guess you could change it to static inline, or just build with -std=gnu89.

Edgar Reynaldo
Member #8,592
May 2007
avatar

I changed it to static inline and it builds fine now. static inline works the same in both gnu89 and gnu11, so that should fix it for all builds.

The offending line is 480 in addons\jpgalleg\src\decode.c :

addons\jpgalleg\src\decode.c#SelectExpand
476/* get_value: 477 * Reads a string of bits from the input stream and returns a properly signed 478 * number given the category. 479 */ 480INLINE int 481get_value(int category) 482{ 483 int result = get_bits(category); 484 if ((result >= (1 << (category - 1))) || (result < 0)) 485 return result; 486 else 487 return result - ((1 << category) - 1); 488}

Do you want a patch, or can you just change it? It's only one keyword.

Here's a patch anyway. get_value_static_fix.diff

torhu
Member #2,727
September 2002
avatar

Maybe the correct solution would be to build with -std=gnu89, as Allegro doesn't use C99 features. Or just using static INLINE, that should work with MSVC too. I'm not an really Allegro dev, so someone else has to do this...

Edgar Reynaldo
Member #8,592
May 2007
avatar

My patch uses static INLINE. MSVC uses __inline, and almsvc.h defines INLINE to be __inline, so there shouldn't be any issues.

Go to: