Why must I use gnu99 instead of c99 to compile a kernel module?
Asked Answered
T

1

8

I am used to using -std=c99 to enable c99 features when compiling application code.

Recently I have been following some basic kernel module examples, and added ccflags-y := -std=c99 to the makefile. However this resulted in 17K lines of errors when I tried to make. gnu99 works perfectly.

What is the difference between gnu99 and c99 that kernel code relies on?

Tilley answered 17/5, 2014 at 3:31 Comment(3)
+1. And you're not the first to notice. See llvm.linuxfoundation.orgAbysmal
Basically, the kernel uses GCC extensions and does not compile when they are turned off.Soricine
What is the difference between gnu99 and c99 that kernel code relies on?. I think you can find these differences yourself. This is from gcc doc: GNU C provides several language features not found in ISO standard C. (The -pedantic option directs GCC to print a warning message if any of these features is used.) . So, build the kernel with gnu99 but add ccflags-y := -pedantic. And then analyze warnings. This is from gcc's doc: gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/…Test
L
1

The linux kernel uses a lot of GCC extensions i.e., the C language used in the kernel is not standards compliant, it is a superset which includes GCC extension. Hence GNU99 is the compiler option which needs to be passed.

Lindbom answered 9/6, 2014 at 2:27 Comment(1)
Actually, the Linux kernel itself is built using gnu89, not gnu99, because of semantic differences (such as the one discussed here: http://www.kernelhub.org/?p=2&msg=606456). Hence, gnu89 should probably also be preferred as standard when making kernel modules, since included kernel-mode headers will likely rely on this standard.Cheerful

© 2022 - 2024 — McMap. All rights reserved.