Thread overview | |||||
---|---|---|---|---|---|
|
December 29, 2011 [dmd-internals] Keywords starting with __ and version identifiers | ||||
---|---|---|---|---|
| ||||
Hi,
DMD currently has two keywords (AFAIK) starting with double
underscore: __traits and __gshared, and additionally, __ctfe (though
it isn't really a keyword)
>From what I can understand, they are implementation-dependent, and
thus not necessarily available in all compilers. This is reasonable enough, but presently, there is no universal way to detect whether the keywords are available. That means that any code that uses them simply relies on the compiler having them, period. I don't think this is optimal, nor is it good language design IMHO.
I think we need to have version identifiers that indicate whether they are available, e.g.:
version (__traits)
{
enum compiles = __traits(compiles, { ... });
}
else
{
// Fall back to some other mechanism, perhaps some feature
provided by a non-DMD compiler...
}
Thoughts on this?
Regards,
Alex
|
December 29, 2011 [dmd-internals] Keywords starting with __ and version identifiers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alex | This could be done in the runtime/phobos - is(typeof()) is standard D, so something like: enum supportsTraits = is(typeof(__traits(compiles, {}))); Could be used. On another note, dmd, gdc and ldc all use DMDFE, and all support the __ keywords mentioned. SDC will also support them... They're so ubiquitous in D code currently they can't *not* be supported. On 29 December 2011 11:56, Alex <xtzgzorex at gmail.com> wrote: > Hi, > > DMD currently has two keywords (AFAIK) starting with double > underscore: __traits and __gshared, and additionally, __ctfe (though > it isn't really a keyword) > > From what I can understand, they are implementation-dependent, and thus not necessarily available in all compilers. This is reasonable enough, but presently, there is no universal way to detect whether the keywords are available. That means that any code that uses them simply relies on the compiler having them, period. I don't think this is optimal, nor is it good language design IMHO. > > I think we need to have version identifiers that indicate whether they are available, e.g.: > > version (__traits) > { > enum compiles = __traits(compiles, { ... }); > } > else > { > // Fall back to some other mechanism, perhaps some feature > provided by a non-DMD compiler... > } > > Thoughts on this? > > Regards, > Alex > _______________________________________________ > dmd-internals mailing list > dmd-internals at puremagic.com > http://lists.puremagic.com/mailman/listinfo/dmd-internals > -- Robert http://octarineparrot.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.puremagic.com/pipermail/dmd-internals/attachments/20111229/13bf69fe/attachment.html> |
December 29, 2011 [dmd-internals] Keywords starting with __ and version identifiers | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alex | On 29 December 2011 12:56, Alex <xtzgzorex at gmail.com> wrote:
> Hi,
>
> DMD currently has two keywords (AFAIK) starting with double
> underscore: __traits and __gshared, and additionally, __ctfe (though
> it isn't really a keyword)
>
> From what I can understand, they are implementation-dependent, and thus not necessarily available in all compilers.
I don't think that's true. I'm not aware that has been stated anywhere.
|
Copyright © 1999-2021 by the D Language Foundation