---
title: CanCast
description: "判断源数据类型是否可以cast到目的数据类型。"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/API/aolapi/atlasascendc_api_07_1159.html
sourcePath: /source/zh/canncommercial/900/API/aolapi/atlasascendc_api_07_1159.html
indexId: 3794a129ce16e1e2da6efd62e7e1f80a308204887faa7851ba763c7963d6f02770
---
# CanCast

#### 功能说明

判断源数据类型是否可以cast到目的数据类型。


#### 函数原型

```
bool CanCast(const DataType from, const DataType to)
```


#### 参数说明

| 参数 | 输入/输出 | 说明 |
| --- | --- | --- |
| from | 输入 | 源数据类型。 |
| to | 输入 | 目的数据类型。 |


#### 返回值说明

若成功cast返回true，否则返回false。


#### 约束说明

无


#### 调用示例

```
// 判断dtype不可以转为int8类型时，返回
void Func(const DataType dtype) {
    if (!CanCast(dtype, DT_INT8)) {
        return;
    }
}
```
