Beside the known ones, like computed gotos and __builtin_expect(), GCC has 
other less known extensions, you can find some of them here:
http://www.ibm.com/developerworks/linux/library/l-gcc-hacks/

They are used by Linux. If D wants to be a system language, such small things 
may be useful if you want to build a kernel with D.

One of them is the Range extension, it seems GCC devs think that 3 points are 
better after all:

        switch (major_idx) {
        case 0:
                return SCSI_DISK0_MAJOR;
        case 1 ... 7:
                return SCSI_DISK1_MAJOR + major_idx - 1;
        case 8 ... 15:
                return SCSI_DISK8_MAJOR + major_idx - 8;
        default:
                BUG();
                return 0;
        }


Triple points can be used for initializations too:
int widths[] = { [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 };


The __builtin_return_address() looks interesting, but I don't understand where 
it can be useful.


The Constant detection done with __builtin_constant_p(exp) is what I was asking 
for in one of my recent posts here. It seems I was "right" again.


The article also shows some of the function attributes, in truth in GCC there 
are many other of such attributes. Some of them are useful for D too.

The good thing of adding some of those things to D is that they can be put in 
the specs, so they don't become nonstandard extensions as in GCC, this avoids 
several troubles. 

Bye,
bearophile

Reply via email to