Re: what is the use of #ifndefs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

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: https://en.wikipedia.org/wiki/Include_guard

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






_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux