Search code examples
cgccsymbolsgcc10

Does native C have common symbol?


In GCC10, gcc default to fno-common. That means, all tentative defined symbols are not common. I think gcc conforms to the C specification but it seems there are no common symbols in the native C program. Are common symbols only for extension syntax?


Solution

  • Does native C have common symbol?

    Read the C11 standard n1570. Its index don't even mention common symbols.

    Read carefully also the documentation of GCC and this draft report.

    Perhaps you refer to the ELF file format used on Linux for object files and executables. There you can find a mention of common symbols, which tend to be deprecated .... Read the Linux ABI specification, etc here.

    My recommendation is to declare all your public symbols as extern in some header file (#include-d in most of your *.c files), and define them once (without extern) in a single translation unit. You could use simple preprocessor tricks (such as X-macros).

    You might be interested in using C code generators such as lemon or SWIG, or develop your script (with GNU awk or Guile or Python or GPP etc... ....) for simple metaprogramming techniques (autoconf could be inspirational) generating some C code. Configure your build automation tool (GNU make, ninja...) suitably.

    You might be interested in using static analyzer options and precompiled headers of recent GCC. Look also into Clang static analyzer and clang tidy and Frama-C.

    You surely want to pass -Wall -Wextra -g -H to gcc and read How to debug small programs and Modern C.