Kuro Burki Kuro Burki - 1 year ago 82
C Question

What is gcc compiler option "-unsigned" meant for?

I am compiling legacy code using gcc compiler 4.8.5 on RHEL7. All C and C++ files have "-unsigned" as one of the default flags for both gcc and g++ compilation. The compiler accepts this option and compiles successfully. However, I cannot find any documentation of this option anywhere either in gcc manual or online. Does anyone know what this option is? I have to port the code and am confused whether this compiler option needs to be ported or not.

Answer Source

I suspect it was just a mistake in the Makefile, or whatever is used to compile the code.

gcc does not support a -unsigned option. However, it does pass options to the linker, and GNU ld has a -u option:

Force SYMBOL to be entered in the output file as an undefined symbol. Doing this may, for example, trigger linking of additional modules from standard libraries. '-u' may be repeated with different option arguments to enter additional undefined symbols. This option is equivalent to the 'EXTERN' linker script command.

The space between -u and the symbol name is optional.

So the intent might have been to do something with unsigned types, but the effect, at least with modern versions of gcc, is to enter nsigned in the output file as an undefined symbol.

This seems to have no effect in the quick test I did (compiling and running a small "hello, world" program). The program runs correctly, and the output of nm hello includes:

                 U nsigned

With an older version of gcc (2.95.2) on a different system, I get a fatal link-time error about the undefined symbol.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download