function pointer and alias questions

Chris R. Miller lordSaurontheGreat at gmail.com
Tue Jul 29 13:44:08 PDT 2008


Michael P. wrote:
> Okay, so I've just started learning D. Set up the DMD 1.033 compiler on my "dev" computer without internet(yeah, it's possible), just used a USB to get all the tutorials/files on the computer. So I was using this tutorial(best beginner one I've found):

If you ever experience problems with your build system, I also make a 
read-to-go toolchain at my site: www.fsdev.net.  You can use that if you 
break something.  I break stuff all the time, so I find myself eating my 
own dogfood quite often :^)

> http://compsci.ca/v3/viewtopic.php?t=9518#
> 
> And I wanted to clear up some things about Function Pointers and Aliases. (It's part 12 of the tutorial, please turn to that part)
> 
> 1. So, alias is just like a way of defining a type write, and with this line:
> 
> alias void function(char[]) GreeterFunction;
> 
> It defines a type named GreeterFunction that is a function that returns nothing and takes a character array/string as an argument?
> 
> 2. This:
> static GreeterFunction[] greeters =
>       [&sayHelloTo, &tellOff, &GreetWithSlang]; 
> 
> creates an array of the type GreeterFunction and places references of the functions in that tutorial example in the array.
> And the static keyword makes the array size fixed at compile time instead of having it be a dynamic array?

Almost.  The const keyword would do that.  Static makes it so that there 
is only one instance of it at run time.  Static does have another dual 
meaning in D though.  A static statement is evaluated at runtime, or 
else it throws an error if it isn't possible to evaluate it at runtime.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 258 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20080729/b480d470/attachment.pgp>


More information about the Digitalmars-d-learn mailing list