Nonstandard GCC features
bearophile
bearophileHUGS at lycos.com
Fri Nov 21 04:43:47 PST 2008
Just found this cute article on Reddit: "GCC hacks in the Linux kernel", by M. Tim Jones:
http://www.ibm.com/developerworks/linux/library/l-gcc-hacks/index.html
Here are few comparisons between those featuers are D ones.
The range syntax that can be used in switch statements and array defintions is cute:
1 ... 7
D2 already has a range syntax, it just needs to be extended for other purposes (and adding a stride too may be useful, but it's less important).
Zero-length arrays are available in D, but the following code (used in C to define a struct with ane or two variable-length arrays) can't be used, because of array bound controls:
struct iso_block_store {
atomic_t refcount;
size_t data_size;
quadlet_t data[0];
};
__builtin_return_address is only for special situations, maybe for kernel code. (While I have found few situations where the computed gotos of GCC are useful).
I think __builtin_constant_p is doable in D2.
deprecated is available in D1:
__attribute__((deprecated))
While the pure functions will become available in D2.
This looks interesting for D too, from the article:
__attribute__((warn_unused_result)) forces the compiler to check that all callers check the result of the function. This ensures that callers are properly validating the function result so that they can handle the appropriate errors.
This may be for special situations only, from the article:
__attribute__((__used__)) tells the compiler that this function is used regardless of whether GCC finds instances of calls to the function. This can be useful in cases where C functions are called from assembly.
__builtin_expect() is of course useful (recently they have extended its usefulness), I have used it few times, it may avoid some of the need of profile-guided optimization.
The article says __builtin_prefetch() is used extensively by the Linux kernel. So far I've never used it yet, because I find its usage not easy and tricky.
Bye,
bearophile
More information about the Digitalmars-d
mailing list