How to pass a int value from C function to SV?

C Code:

extern "C" int GetRndcfgData(string path) {
    printf ("soc_init::GetRndcfgData--1 ");
    string rndcfg_str;
    long int rndcfg_value;
    printf ("soc_init::GetRndcfgData--11 ");
    printf ("%s path", path);
    path += "@"; 
    printf ("soc_init::GetRndcfgData--2 ");
    for(it1=rndcfg_map.begin(); it1!=rndcfg_map.end(); ++it1) {
    printf ("soc_init::GetRndcfgData--3 ");
        rndcfg_str = it1->first;
        if(rndcfg_str.find(path) != string::npos) {
          break;
          printf ("soc_init::GetRndcfgData--4 \n ");
        }    
    }
    printf ("soc_init::GetRndcfgData out of for loop \n ");
    if(it1 == rndcfg_map.end()) { 
        printf ("No rndcfg data found for register %s\n",path.c_str());
        rndcfg_value = 0xBADC0FFE; //need to see some default value or may print eror if reg not found in rndcfg
    } else {
        rndcfg_value = it1->second;
    printf ("soc_init::GetRndcfgData rndcfg value is  %x",rndcfg_value);
    }
    printf ("%s rndcfg_value=%x",path.c_str(),rndcfg_value);
    return rndcfg_value;
}


extern "C" void ReadRndcfg() {
    string key,line;
    uint32_t val;
    char* filename = new char[256];
    filename = getcwd(filename, 255);
    strcat(filename, "/rndcfg.cfg");
    cout << "soc_init::Reading rndcfg file=" << filename << '\n';
    ifstream fin (filename);
    if(!fin.is_open()) {
        printf ("Unable to open file %s",filename);
        //return 1;
    }
    while( getline(fin,line)) { //fin >> key >> hex >> val) 
        istringstream str(line);
        if(line.find("//") == string::npos) {
            str >> key >> hex >> val;
            key += "@";
            //transform(key.begin(), key.end(), key.begin(), ::toupper);
            rndcfg_map[key] = val;
    cout << "soc_init::ReadRndcfg out of while loop=" << rndcfg_map[key] <<'\n';
        }
    }
    printf ("soc_init::ReadRndcfg out of while loop");
    //for(it1=rndcfg_map.begin(); it1!=rndcfg_map.end(); ++it1) {
    //    std::cout << it1->first << " " << hex << it1->second << '\n';
    //}
    fin.close();
    printf ("soc_init::ReadRndcfg function done");
    //return 0;
}

SV Code:

import "DPI-C" function int GetRndcfgData(string path);
import "DPI-C" function void ReadRndcfg();

module tb();

initial begin 
reg initpkg;
reg smten;
    ReadRndcfg();
initpkg = GetRndcfgData("sys.PMREG_INITPKG7");
$display ("%d", initpkg);
smten   = GetRndcfgData("sys.PMREG_INITPKG0.SMTEN");  
$display ("%d", smten);
end
endmodule

this code is giving me stack trace…

can someone help me what would be the problem.

In reply to VerificationLearn:

It would help if you showed the stacktrace and all files needed to run the code.

Also, you defined rndcfg_value as long int, yet the return value is int.

— Stack trace follows:

Dumping VCS Annotated Stack:
#0 0x55555430 in __kernel_vsyscall ()
#1 0x00451303 in __waitpid_nocancel () from /lib/libc.so.6
#2 0x003eac53 in do_system () from /lib/libc.so.6
#3 0x0055798d in system () from /lib/libpthread.so.0
#4 0x559c9bd0 in SNPSle_10ee25eff68cd8461c9146fa1d0b35e87067f3c8015b313e639d2928478c79b3f673f99203bcf8be64600612100082236bffb2007f1e0ef9 () from /tool/cbar/apps/vcs-mx/2017.03-SP2-5/linux/lib/liberrorinf.so
#5 0x559cb426 in SNPSle_10ee25eff68cd8461c9146fa1d0b35e87067f3c8015b313efba706aab251478fa49e66610e453774633a6c152e7ef778f2202cda681f3d4e () from /tool/cbar/apps/vcs-mx/2017.03-SP2-5/linux/lib/liberrorinf.so
#6 0x559c398d in SNPSle_d35ca1ff70d465c2b9b1a72eee90a506fdd009d3de3db1de () from /tool/cbar/apps/vcs-mx/2017.03-SP2-5/linux/lib/liberrorinf.so
#7 0x5750298e in SNPSle_64133461705005bb725549e2e6fa1b3f () from /tool/cbar/apps/vcs-mx/2017.03-SP2-5/linux/lib/libvcsnew.so
#8 0x5734e0e4 in SNPSle_82244d58c54c18c70d63edc9becab634 () from /tool/cbar/apps/vcs-mx/2017.03-SP2-5/linux/lib/libvcsnew.so
#10 0x55555430 in __kernel_vsyscall ()
#11 0x003da871 in raise () from /lib/libc.so.6
#12 0x003dc14a in abort () from /lib/libc.so.6
#13 0x00420cb3 in malloc_printerr () from /lib/libc.so.6
#14 0x00425ee0 in free () from /lib/libc.so.6
#15 0x5ab60978 in operator delete (ptr=0x7379732d) at …/…/…/…/…/libstdc+±v3/libsupc++/del_op.cc:49
#16 0x5ac1ed34 in __gnu_cxx::new_allocator::deallocate (this=0x5c649758, __p=) at /tmp/gcc630/gcc-6.3.0/build/x86_64-pc-linux-gnu/32/libstdc+±v3/include/ext/new_allocator.h:110
#21 0x5ac20731 in std::__cxx11::basic_string<char, std::char_traits, std::allocator >::_M_append (this=0x5c649758, __s=0x80c98fa “Z”, __n=1) at /tmp/gcc630/gcc-6.3.0/build/x86_64-pc-linux-gnu/32/libstdc+±v3/include/bits/basic_string.tcc:370
#22 0x0804d543 in GetRndcfgData ()
#23 0x5556a5dc in F_VCSgd_jNxLu_3_0 () from /home/sgangi/readrndcfg/svcpp/simv.daidir/_prev_archive_1.so
#24 0x5556a8ef in N_VCSgd_g7hgQ () from /home/sgangi/readrndcfg/svcpp/simv.daidir/_prev_archive_1.so
#25 0x5556a835 in N_VCSgd_g7hgQ () from /home/sgangi/readrndcfg/svcpp/simv.daidir/_prev_archive_1.so
#26 0x574ba42a in SNPSle_63c7abb936d47b07d29d61775f9dbe8c () from /tool/cbar/apps/vcs-mx/2017.03-SP2-5/linux/lib/libvcsnew.so
#27 0x5752c96b in SNPSle_490598bfebcc8e81 () from /tool/cbar/apps/vcs-mx/2017.03-SP2-5/linux/lib/libvcsnew.so
#28 0x555709f7 in main () from /home/sgangi/readrndcfg/svcpp/simv.daidir/_csrc0.so
#29 0x003c6d36 in __libc_start_main () from /lib/libc.so.6
#30 0x0804d401 in _start ()

i have changed long int to int … still i am getting the same …

i am suspecting that somehow where we have the
path += “@”; this isnt working fine?

not sure though … can someone help me out why is it happening?