Friday, February 1, 2008

Wow HP-UX's aCC compiler is annoying...

You know how a traditional C compiler toolchain is typically a series of tools "chained" together. Typically it's something like:

preprocessor->compiler->assembler->linker

This architecture suggests that you should be able to feed the output of one link into another. Not so with the aCC compiler that comes with HP-UX 11.0.

Check out the nice little C program (it's a proof-of-concept resulting from several hours of analysis into a problem building Perl):

#include <inttypes.h>

int main()
{
return UINT32_MAX ;
}

Compiling this with aCC shows some sort of problem with macro expansion during proprocessing:

bash-2.04# aCC -c foo.c
Error 20: "foo.c", line 5 # ';' expected before 'l'.
return UINT32_MAX ;
^^^^^^^^^^
Error 172: "foo.c", line 5 # Undeclared variable 'l'.
return UINT32_MAX ;
^^^^^^^^^^

So it's natural to want to see what the code looks like after preprocessing:

bash-2.04# aCC -E foo.c > out.c
bash-2.04# cat out.c
....
int main()
{
return 4294967295ul ;
}

Simple enough. Perhaps it doesn't handle "ul" as a type? This is where it gets interesting. The above preprocessed code compiles without any issue.

bash-2.04# aCC -c out.c
bash-2.04#

In other words, with HP-UX's compiler:

aCC -c foo.c

is not the same thing as:

aCC -E foo.c > out.c
aCC -c out.c

Very annoying.