www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - can I alias something to void?

reply torhu <fake address.dude> writes:
I'm translating some C headers.


#define AL_CONST const

void set_window_title(AL_CONST char *name) { /* ... */ }


I'm wondering if there is a legitimate way to turn AL_CONST into nothing 
in D.  This compiles:

alias void AL_CONST;

void set_window_title(AL_CONST char *name) { /* ... */ }


But I have no idea if that screws up the parameter type somehow, or if 
it's legal according to the D spec.

Of course I could delete the AL_CONST's.  But I'm just curious.
Jan 17 2007
next sibling parent reply torhu <fake address.dude> writes:
torhu wrote:
 I'm translating some C headers.
 
 
 #define AL_CONST const
 
 void set_window_title(AL_CONST char *name) { /* ... */ }
 
 
 I'm wondering if there is a legitimate way to turn AL_CONST into nothing 
 in D.  This compiles:
 
 alias void AL_CONST;
 
 void set_window_title(AL_CONST char *name) { /* ... */ }
 
Eh...seems the compiler doesn't accept 'AL_CONST char *' after all. Sorry about that. I'm still interested in other ways of doing this, though.
Jan 17 2007
parent Mike Parker <aldacron71 yahoo.com> writes:
torhu wrote:
 torhu wrote:
 I'm translating some C headers.


 #define AL_CONST const

 void set_window_title(AL_CONST char *name) { /* ... */ }


 I'm wondering if there is a legitimate way to turn AL_CONST into 
 nothing in D.  This compiles:

 alias void AL_CONST;

 void set_window_title(AL_CONST char *name) { /* ... */ }
Eh...seems the compiler doesn't accept 'AL_CONST char *' after all. Sorry about that. I'm still interested in other ways of doing this, though.
You don't need it. Just drop the 'const' altogether: void set_window_title(char* name) { } Of course, if this is a pure D port of a C program, you'd be better served with this form: void set_window_title(char[] name) {} And if it is a binding to a C library, this form: extern(C) void set_window_title(char* name);
Jan 17 2007
prev sibling parent Stewart Gordon <smjg_1998 yahoo.com> writes:
torhu wrote:
 I'm translating some C headers.
 
 #define AL_CONST const
 
 void set_window_title(AL_CONST char *name) { /* ... */ }
 
 I'm wondering if there is a legitimate way to turn AL_CONST into nothing 
 in D.  This compiles:
Not as such, because D by design has a context-free grammar. Defining an identifier to resolve to textual nothingness would affect the parsing.
 alias void AL_CONST;
 
 void set_window_title(AL_CONST char *name) { /* ... */ }
<snip> Another tip: In D pointer declarations, the '*' is strictly associated with the type. So char* name is a preferred style to char *name Stewart.
Jan 17 2007