digitalmars.D - Feature Request: Keyword as identifier.
- icee (9/9) Sep 29 2006 In C# we can use a keyword as a identifier by prefixing @
- Frits van Bommel (8/18) Sep 29 2006 Actually, there's another option: create a C wrapper around it with
- Charlie (2/24) Sep 29 2006
- Stewart Gordon (13/23) Sep 29 2006 See also my proposal for an alternative solution:
- icee (13/14) Sep 30 2006 Fortunately i don't have to handle this in the real cases right now.
- Don Clugston (6/16) Oct 02 2006 I proposed a keyword called 'identifier':
- Stewart Gordon (12/19) Oct 02 2006 What practical uses are there for token pasting in D?
- J Duncan (5/21) Oct 02 2006 I can think of many uses of token pasting, the most obvious to allow a
Why? suppose we are using a extern C lib, the library exports a function as "int version()", so we write: extern(C) int version(); this will obviously fail to compile, cos' version is a D keyword, (but not the C keyword.) so we have no methods except modify the C code and re-compile it.
Sep 29 2006
icee wrote:Why? suppose we are using a extern C lib, the library exports a function as "int version()", so we write: extern(C) int version(); this will obviously fail to compile, cos' version is a D keyword, (but not the C keyword.) so we have no methods except modify the C code and re-compile it.Actually, there's another option: create a C wrapper around it with another name. #include "whatever/version.h" int C_version() { return version(); } Doesn't help much perhaps, but doesn't require recompilation. Which is good if you don't have the source of the lib to do so, for instance. Plus this might compile a lot faster than the lib ;).
Sep 29 2006
I think you can also alias it in the .def file ? Frits van Bommel wrote:icee wrote:Why? suppose we are using a extern C lib, the library exports a function as "int version()", so we write: extern(C) int version(); this will obviously fail to compile, cos' version is a D keyword, (but not the C keyword.) so we have no methods except modify the C code and re-compile it.Actually, there's another option: create a C wrapper around it with another name. #include "whatever/version.h" int C_version() { return version(); } Doesn't help much perhaps, but doesn't require recompilation. Which is good if you don't have the source of the lib to do so, for instance. Plus this might compile a lot faster than the lib ;).
Sep 29 2006
icee wrote:Why? suppose we are using a extern C lib, the library exports a function as "int version()", so we write: extern(C) int version(); this will obviously fail to compile, cos' version is a D keyword, (but not the C keyword.)"cos'"?so we have no methods except modify the C code and re-compile it.See also my proposal for an alternative solution: http://tinyurl.com/gsan2 Stewart. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/M d- s:- C++ a->--- UB P+ L E W++ N+++ o K- w++ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++++ h-- r-- !y ------END GEEK CODE BLOCK------ My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Sep 29 2006
Fortunately i don't have to handle this in the real cases right now. Thanks for all the suggestions. Wrapper like "C_version" maybe is a little ugly,:) and not convenient enough. Your proposal about extren(...) may be a good solution, and focus on the foreign symbol name. What i'm requesting is the general ability to use any reserved word as identifier in D codes, Because of the complexity of D language, it require more words to be reserved. this may break the programmer's naming rule and convenience. I think allowing keyword as id may improve the user experience. version? $version? (...any)? or some what ?"cos'"?I mean "because" Coz My poor and lazy En;)
Sep 30 2006
icee wrote:Why? suppose we are using a extern C lib, the library exports a function as "int version()", so we write: extern(C) int version(); this will obviously fail to compile, cos' version is a D keyword, (but not the C keyword.) so we have no methods except modify the C code and re-compile it.I proposed a keyword called 'identifier': extern(C) int identifier("version")(); As well as solving this problem, it would add the most powerful remaining C preprocessor feature (token pasting) into the D template system. Serious magic. Although D has no shortage of magic already <g>.
Oct 02 2006
Don Clugston wrote: <snip>I proposed a keyword called 'identifier': extern(C) int identifier("version")(); As well as solving this problem, it would add the most powerful remaining C preprocessor feature (token pasting) into the D template system. Serious magic. Although D has no shortage of magic already <g>.What practical uses are there for token pasting in D? Stewart. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/M d- s:- C++ a->--- UB P+ L E W++ N+++ o K- w++ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++++ h-- r-- !y ------END GEEK CODE BLOCK------ My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Oct 02 2006
Stewart Gordon wrote:Don Clugston wrote: <snip>I can think of many uses of token pasting, the most obvious to allow a mixin to programatically create identifiers (which would be a boon to the severely limited mixins). combine it with reflection and you have all sorts of fun options with generating codeI proposed a keyword called 'identifier': extern(C) int identifier("version")(); As well as solving this problem, it would add the most powerful remaining C preprocessor feature (token pasting) into the D template system. Serious magic. Although D has no shortage of magic already <g>.What practical uses are there for token pasting in D? Stewart.
Oct 02 2006