Search
SystemC Tutorial
SystemC Introduction
SystemC Hello World
SystemC Functions SystemC Data Types
SystemC Operators
Functions SystemC Statement and Flow Control
SystemC Jump Statements
function is group of statements to perform the specific task. SystemC Functions
SystemC Functions argument passing
Syntax:
SystemC Modules
type function_name (arguments) {
function_body; Contact / Report an issue
} Your valuable inputs are
required to improve the quality.
where,
type – functions will return an value, type specifies the return type
function_name – name of the function Follow Us
arguments – arguments to the function
function_body – body of the function, which may contain declarations, assignments, expressions etc.
function can return a specific value by specifying return in function body, otherwise the result of last
expression will be returned.
Example1:
#include "systemc.h"
//function add, to add two integer numbers
int add (int a,int b)
{
return a+b;
}
int sc_main (int argc, char* argv[]) {
//declaration
int x,y,z;
//initialization
x=10;
y=20;
//function calling
z = add(x,y);
cout <<" x+y = "<<z<<endl;
// Terminate simulation
return 0;
}
Simulator Output:
x+y = 30
Execute the above code on
void functions
Generally functions will return an value, where as void functions will not return any value.
by specifying type as void function can be declared as void function.
Example1:
#include "systemc.h"
//function add, to add two integer numbers
void display (int a,int b)
{
cout <<" recived a = "<<a<<" b = "<<b<<endl;
}
int sc_main (int argc, char* argv[]) {
//function calling
display(10,20);
// Terminate simulation
return 0;
}
Simulator Output:
recived a = 10 b = 20
Execute the above code on
function call as expression
Example1:
#include "systemc.h"
//function add, to add two integer numbers
int add (int a,int b)
{
return a+b;
}
int sc_main (int argc, char* argv[]) {
//declaration
int x,y,z;
//initialization
x=10;
y=20;
//function call in expression
z = 10 + add(x,y) + 20;
cout <<" Value of z = "<<z<<endl;
// Terminate simulation
return 0;
}
Simulator Output:
Value of z = 60
Execute the above code on
functions declaration
Example1:
#include "systemc.h"
//function display_1
void display_1 ()
{
display_2;
}
//function display_1
void display_2 ()
{
display_1;
}
int sc_main (int argc, char* argv[]) {
// Terminate simulation
return 0;
}
Simulator Output:
testbench.cpp: In function 'void display_1()':
testbench.cpp: error: 'display_2' was not declared in this scope
Exit code expected: 0, received: 1
Execute the above code on
The above example is locked situation where as display_1 is calling display_2 and display_2 is calling
display_1, this leads to an compilation error.
This problem can be overcome by declaring the functions and writing the definitions separately.
Arguments and type must match in declaration and definition.
Example2:
#include "systemc.h"
void display_1();
void display_2();
//function display_1
void display_1 ()
{
display_2();
}
//function display_1
void display_2 ()
{
display_1();
}
int sc_main (int argc, char* argv[]) {
cout <<"Inside Main"<<endl;
// Terminate simulation
return 0;
}
Simulator Output:
Inside Main
Execute the above code on
© Copyright 2016 Verification Guide. All rights reserved.