# How can I use a DPI C function within a class

**URL:** <https://verificationacademy.com/forums/t/how-can-i-use-a-dpi-c-function-within-a-class/31564>\
**Category:** SystemVerilog\
**Tags:** import, SystemVerilog, System-Verilog, DPI, imported-c-function\
**Created:** [March 2, 2016, 8:13am UTC](https://verificationacademy.com/forums/t/how-can-i-use-a-dpi-c-function-within-a-class/31564 "2016-03-02T08:13:41Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![RenéPi](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/r/e47c2d/32.png) [@RenéPi](https://verificationacademy.com/forums/u/Ren%C3%A9Pi)\
**Post date:** [March 3, 2016, 8:55am UTC](https://verificationacademy.com/forums/t/how-can-i-use-a-dpi-c-function-within-a-class/31564/3 "2016-03-03T08:55:59Z")

</div>

Thanks a lot for the reply Dave!

I have now imported the C function outside the class with:

import “DPI-C” context function CCRC32\_crcbitbybit();

I am calling the C function by calling a function within the System Verilog class

function imp\_func(byte data);

```
 longint crc_ret = 0;

$display("Importing C Function");
crc_ret = CCRC32_crcbitbybit();
$display("Return Vaule of CCRC32: %h",crc_ret);

```

endfunction

I have another question regarding datatypes between SV and C:

The CRC C function uses an **unsigned char** \* which compares to be a **string** in SV, but I am using a **byte** as Parameter for the SV function.

Is there any possibility to convert a byte to a string in SV?

Thanks a lot,  
René

_In reply to [dave\_59](https://verificationacademy.com/forums/t/how-can-i-use-a-dpi-c-function-within-a-class/31564/2):_

---

_[View the full topic](https://verificationacademy.com/forums/t/how-can-i-use-a-dpi-c-function-within-a-class/31564)._
