User guide

18-3
DirectC Interface
Using Direct C/C++ Function Calls
To enable a direct call of a C/C++ function during simulation, do the
following:
1. Declare the function in your Verilog code.
2. Call the function in your Verilog code.
3. Compile your Verilog and C/C++ code using compile-time options
for DirectC.
However there are complications to this otherwise straightforward
procedure.
DirectC allows the invocation of C++ functions that are declared in
C++ using the extern "C" linkage directive. The extern "C"
directive is necessary to protect the name of the C++ function from
being mangled by the C++ compiler. Plain C functions do not undergo
mangling, and therefore do not need any special directive.
The declaration of these functions involves specifying a direction for
the parameters of the C function. This is because, in the Verilog
environment, they become analogous to Verilog tasks as well as
functions. Verilog tasks are like void C functions in that they don’t
return a value. Verilog tasks do however have input, output, and inout
arguments, whereas C function parameters do not have explicitly
declared directions. See "Declaring the C/C++ Function" on page
18-6.