# Exact difference between $cast as a task and function

**URL:** <https://verificationacademy.com/forums/t/exact-difference-between-cast-as-a-task-and-function/31392>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, function, task, cast\
**Created:** [January 11, 2016, 6:21am UTC](https://verificationacademy.com/forums/t/exact-difference-between-cast-as-a-task-and-function/31392 "2016-01-11T06:21:24Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![bdreku](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/bdreku/32/4520_2.png) [@bdreku](https://verificationacademy.com/forums/u/bdreku)\
**Post date:** [January 11, 2016, 6:49am UTC](https://verificationacademy.com/forums/t/exact-difference-between-cast-as-a-task-and-function/31392/2 "2016-01-11T06:49:01Z")

</div>

_In reply to [paragsathe](https://verificationacademy.com/forums/t/exact-difference-between-cast-as-a-task-and-function/31392):_

When $cast() is used as a task and the casting fails, SV prints a run-time error.  
i.e.

```auto
$cast(A,B);

```

When $cast() is used as a function and if casting fails, it returns value “0” and in the case of successful casting, it returns value “1”.  
i.e.

```auto
if($cast(A,B)) $display("It's a successful casting");
else $display("casting is failed");

```

---

_[View the full topic](https://verificationacademy.com/forums/t/exact-difference-between-cast-as-a-task-and-function/31392)._
