idtypes.idl is used to provide static type checking for all types, including intrinsic types such as int, float, short, double. This is basically a type-safe typedef. Let’s say you're using a LONG to represent a user ID. Ordinarily, you'd just use the LONG data type in all your APIs. This isn't type safe because someone can pass in *any* LONG value -- and not necessary a user ID. To create a new type for user ID, add to this your IDL:


Now use USERID_LONG as your type in IDL or C/C++. It's just as efficient as using a LONG but the compiler will complain unless the client passes in a USERID_LONG.

This page is an example of Catching defects with Patterns.

Community content is available under CC-BY-SA unless otherwise noted.