what is the use of #ifndefs

Aruna Hewapathirane aruna.hewapathirane at gmail.com
Tue Jul 21 15:44:58 EDT 2015

>> I dont understand what goal is it supposed to achieve
>> at the beginning of the headerfile

The 'goal' is to prevent 'redefinition' errors, like Stephan Müller said it
is a 'include guard'.

A explanation of why and how to use include guards can be found here:

When I try : find . -name "*.c" -o -name "*.h" | xargs grep -i "include
<linux/list.h>" | wc -l

It gives me 1319 instances where list.h is being included, imagine your
function being redefined that many times. Not only will gcc bitch and
complain about redefinition errors but go screaming into the night like
Valdis says.. [grin]

If you still have difficulty understanding why, the best way would be to
write some simple code yourself then compile, you will start to see why we
require the #ifndef.

Thanks - Aruna
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20150721/dffcd221/attachment.html 

More information about the Kernelnewbies mailing list