March 20, 2005
On Sun, 20 Mar 2005 23:05:29 +0000 (UTC), AEon <AEon_member@pathlink.com> wrote:
> Regan Heath:
>
>> Personally I would use something like:
>>   alias std.file.read read;
>>
>> but I would not use:
>>   alias std.file.read bob;  //or anything other than 'read'
>>
>> because IMO alias is used to shorten the code and make it easier to
>> follow. Changing the name of a well known function to something else makes
>> it harder to follow the code. ...
>
> Ok... does the above alias have some evil side effects (type checking no longer working e.g.), like the #define in C used to do?

The one above, no, not as far as I can see. Firstly, because it doesn't alias types, and secondly even if it did...

http://www.digitalmars.com/d/declaration.html
"Type aliases are equivalent to the C typedef."

So "alias" is more similar to "typedef" than "define". The biggest reason is that "define" was handled by the pre-processor, effectively doing a find/replace on the source *before* the compiler sees it.

http://www.digitalmars.com/d/declaration.html
"Aliased types are semantically identical to the types they are aliased to. The debugger cannot distinguish between them, and there is no difference as far as function overloading is concerned. For example:

alias int myint;

void foo(int x) { . }
void foo(myint m) { . }error, multiply defined function foo"

So, AIUI "alias" creates a new name for a type, which is treated identically to the old name. "typedef" actually creates a new type.

Regards,
Regan
1 2
Next ›   Last »