www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Feature Request: Keyword as identifier.

reply "icee" <iceelyne gmail.com> writes:


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
next sibling parent reply Frits van Bommel <fvbommel REMwOVExCAPSs.nl> writes:
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
parent Charlie <charlies nowhere.com> writes:
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
prev sibling next sibling parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
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
parent "icee" <iceelyne gmail.com> writes:
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
prev sibling parent reply Don Clugston <dac nospam.com.au> writes:
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
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
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
parent J Duncan <me nospam.com> writes:
Stewart Gordon wrote:
 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.
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 code
Oct 02 2006