DMD 1.005 release

janderson askme at me.com
Tue Feb 6 20:36:18 PST 2007


Walter Bright wrote:
> janderson wrote:
>> The import stuff has been part of C for a long time (in the form of 
>> #include), however I've never seen it used.  Maybe with string 
>> operations it will be useful, but otherwise I don't see the point.
> 
> The fundamental difference is that #include inserts *program text*, 
> while import inserts the contents as a *string literal*.
> 
> Some things that you can do with import that you cannot do with #include:
> 
> 1) You can have tech writers write "help text" files, which can then be 
> imported by the programmers as string literals. This means the tech 
> writers do not have to be concerned in the slightest with string syntax.

They could just add quotes around them in C.  Slightly less convenient, 
never seen anyone use that feature.

> 
> 2) It's an easy way to bind binary data into a program. For example, 
> let's say one wants to embed an icon (.ico) file into your program 
> binary. In C, one would have to write:
> 
>     static unsigned char icon[] = { 0x00, 0x10, 0x53, 0x29, ... };
> 
> meaning one must translate the binary data in foo.ico to the hex notation.
> 
> In D, one can write:
> 
>     static ubyte[] icon = cast(ubyte[])import("foo.ico");

This is a good point.  Maybe it should be on the webpage.

-Joel



More information about the Digitalmars-d-announce mailing list