What GNU C extensions are available that are not trivial to implement on C99?

Why can the Linux kernel only compile with GCC? What GNU C extensions are really needed for some projects, and why?

+6
c gcc linux c99 language-extension
source share
5 answers

This article explains the extensions used: GCC hacks in the Linux kernel . Some of them are trivial, some of them (mostly optimization tricks).

+8
source share

Here are a few gcc extensions for the Linux kernel:

  • build assembly
  • gcc builtins such as __builtin_expect, __ builtin_constant, __ builtin_return_address
  • function attributes to indicate, for example. what is registered for use (e.g. __attribute __ ((regparm (0)), __ attribute __ ((packed, aligned (PAGE_SIZE)))))
  • specific code depending on predefined gcc macros (e.g. workarounds for specific gcc errors in certain versions)
  • ranges in switch cases (case 8 ... 15 :)

Here are a few more: http://www.ibm.com/developerworks/linux/library/l-gcc-hacks/

Most of these gcc specifications are very architecture dependent or made possible by the implementation of gcc, and it probably doesn't make sense to use the C standard. Others are just convenient extensions for C. Since the Linux kernel is built to rely on these extensions, others compilers must provide the same extensions as gcc in order to be able to build the kernel.

This is not what Linux had to rely on these gcc features, for example. NetBSD kernel has very little to do with specific gcc materials.

+7
source share

The Linux kernel was written to compile GCC, so standard compliance was never a goal for kernel developers.

And if GCC offers some useful extensions that simplify or compile the kernel with less or faster conversion, it was a natural choice to use these extensions.

+2
source share

GCC supports Nested functions that are not part of the C99 standard. However, some analysis is needed to see how common they really are in the linux kernel.

+1
source share

I think this is not how it should be. There are simply a lot of useful ones, and portability of cross-compilers is not a problem for the Linux kernel to give up subtleties. Not to mention how much effort it will take to get rid of the use of extensions.

0
source share

All Articles