DMD 1.005 release

Walter Bright newshound at digitalmars.com
Tue Feb 6 10:07:23 PST 2007


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.

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");



More information about the Digitalmars-d-announce mailing list