Last update Sep 12, 2002
#include <stdio.h>
import stdio;
#pragma onceor the more portable:
#ifndef __STDIO_INCLUDE #define __STDIO_INCLUDE ... header file contents #endif
struct Foo { align (4): // use 4 byte alignment ... }
#define VALUE 5
const int VALUE = 5;
int flags: #define FLAG_X 0x1 #define FLAG_Y 0x2 #define FLAG_Z 0x4 ... flags |= FLAGS_X;
enum FLAGS { X = 0x1, Y = 0x2, Z = 0x4 }; FLAGS flags; ... flags |= FLAGS.X;
#if UNICODE #define dchar wchar_t #define TEXT(s) L##s #else #define dchar char #define TEXT(s) s #endif ... dchar h[] = TEXT("hello");
import dchar; // contains appropriate typedef for dchar ... dchar[] h = "hello";D's optimizer will inline the function, and will do the conversion of the string constant at compile time.
#if PROTOTYPES #define P(p) p #else #define P(p) () #endif int func P((int x, int y));
#define INT int
alias int INT;
#define EXTERN extern #include "declations.h" #undef EXTERN #define EXTERN #include "declations.h"In declarations.h:
EXTERN int foo;
#define X(i) ((i) = (i) / 3)
int X(int i) { return i = i / 3; }The compiler optimizer will inline it; no efficiency is lost.
#define assert(e) ((e) || _assert(__LINE__, __FILE__))
#ifndef _CRTAPI1 #define _CRTAPI1 __cdecl #endif #ifndef _CRTAPI2 #define _CRTAPI2 __cdecl #endif int _CRTAPI2 func();
extern (Windows) { int onefunc(); int anotherfunc(); }
#define LPSTR char FAR *
#ifdef UNICODE int getValueW(wchar_t *p); #define getValue getValueW #else int getValueA(char *p); #define getValue getValueA #endif
version (UNICODE) { int getValueW(wchar[] p); alias getValueW getValue; } else { int getValueA(char[] p); alias getValueA getValue; }