---
title: OSDynamicCast
framework: driverkit
role: symbol
role_heading: Macro
path: driverkit/osdynamiccast
---

# OSDynamicCast

Casts an object safely to the specified type, if possible.

## Declaration

```occ
#define OSDynamicCast(type, inst)
```

## Parameters

- `type`: The name of the desired class type as a raw token, not as a string or macro.
- `inst`: The object to cast to the specified type.

## Return Value

Return Value The object cast to the specified type, or NULL if the cast could not be performed safely.

## Discussion

Discussion Use this macro instead of the standard C++ RTTI type-casting operator to cast objects to specific types. The following example shows how to cast some object to the OSString class. If the object cannot be cast to a string, the macro sets the string variable to NULL. OSString string = OSDynamicCast(OSString, anObject)

## See Also

### Runtime support

- [OSRequiredCast](driverkit/osrequiredcast.md)
- [IMPL](driverkit/impl.md)
- [TYPE](driverkit/type.md)
- [QUEUENAME](driverkit/queuename.md)
- [SUPERDISPATCH](driverkit/superdispatch.md)
- [IIG_KERNEL](driverkit/iig_kernel.md)
- [LOCAL](driverkit/local.md)
- [LOCALONLY](driverkit/localonly.md)
- [Error Codes](driverkit/error-codes.md)
- [C++ Runtime Support](driverkit/c-runtime-support.md)
