Re: why test for "__GNUC__"?

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

 



On Oct 29, 2006, at 22:38:34, Adrian Bunk wrote:
for better or worse, i generally assume that whatever i'm looking at is there for a *reason* and i might spend some time puzzling over a bit of code until it finally dawns on me that it's just historical cruft that has no value. it's not a bug, it just doesn't *do* anything anymore.

in my case, it's sometimes easier to spot things like this since i'm following along in some book, like r. love's "linux kernel development." so when he writes that the linux kernel is wedded to gcc, and yet i see tests for "__GNUC__" throughout the code, my little antenna stalks perk up a bit.

Looking at it, it seems I might look through them - some of them seem to be really pointless.

One other thing of note is that certain linux kernel headers _are_ used by userspace (albeit in a number of cases legacy userspace), and as a result we need to ensure that they continue to build on the variety of compilers currently used in userspace. Naturally this doesn't apply to everything, but see the recent threads involving (IIRC) some part of KDE and indirectly <linux/types.h>. From what Linus has stated in the past it sounds like his goal is to make the user<=>libc interface completely 100% separated from the libc<=>kernel interface such that neither includes the other, but a lot of older userspace violates those assumptions. As a result, if we want older versions of libc's to continue to work in various compilers with newer kernel headers we need to maintain some of that "compatibility cruft".

That said, if __GNUC__ is mentioned inside __KERNEL__ in anything other than a version test then it should probably be removed. To that end these little macros in <linux/compiler.h> might make it a bit more obvious what's being tested and make it easier to grep for:

#ifdef __KERNEL__
# define GCC_VERSION ((__GNUC__ << 24) | \
	(__GNUC_MINOR__ << 16) | \
	(__GNUC_PATCHLEVEL__))
# define GCC_AT_LEAST(x,y,z) (GCC_VERSION >= (((x)<<24)|((y)<<16)|(z)))
# define GCC_OLDER_THAN(x,y,z) (!GCC_AT_LEAST(x,y,z))
#endif

There's also the kernelnewbies list.

But your emails are not as bad as you think - the email starting this thread as well as your earlier emails regarding menu structure etc. have some value (and they are better than many other questions that hit this list...).

I personally tend to agree; seems like some of this cruft is just accepted status-quo because it would be so tedious and git-queue- blocking to go through and clean it all up.

Cheers,
Kyle Moffett

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux