• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Functional Verification
  3. Passing struct as an argument

Stats

  • Locked Locked
  • Replies 9
  • Subscribers 65
  • Views 22610
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Passing struct as an argument

archive
archive over 19 years ago

Hi,
I am trying my hand on DPI, and have an example in which i want to pass a struct as an argument to 'C'. however i am not getting any results.

**********************************

The code is:

// Program to pass struct data-type as an argument.
// Author: Vivek C. Prasad
// Date  : 20 september 2006

#include
#include "svdpi.h"

  typedef struct {
    char a;
    int b;
    } AB;

  AB sc;
  int str(const AB sc) {
       printf("the byte is: %c\n",sc.a);
       printf("the int is: %d\n",sc.b);
       return(-1);
       }

**********************************

// Program to pass struct data-type as an argument.
// Author: Vivek C. Prasad
// Date  : 20 september 2006

module structPass();
 
  int res;
  typedef struct packed {
    byte a;
    shortint b;
    } AB;

  AB dt_struct;
 
  import "DPI-C" context str = function int structFunction(input dt_struct);

  initial begin
    dt_struct.a = "V";
    dt_struct.b = 10;
    res = structFunction(dt_struct);
    $display("The struct is passed as an argument.\n");
    $display("Byte: %0d\n",dt_struct.a);
    $display("Int : %0d\n",dt_struct.b);
    $display("Return : %0d\n",res);
  end
endmodule

**********************************
The Result is:

the byte is:
the int is: 0
The struct is passed as an argument.

Byte: 86

Int : 10

Return : -1

**********************************

Vivek.


Originally posted in cdnusers.org by prasad_vc
  • Cancel
Parents
  • archive
    archive over 17 years ago

    The reversing of the struct is apparently deliberate and universal across all simulators, but I can't remember why it's meant to happen. The fun thing is that packed and unpacked structs behave differently - i.e. one reverses, the other doesn't.
    Hopefully one of the simulator gurus can explain.
    If I can find the original explanation from a couple of years ago, I'll post that too...


    Originally posted in cdnusers.org by stephenh
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • archive
    archive over 17 years ago

    The reversing of the struct is apparently deliberate and universal across all simulators, but I can't remember why it's meant to happen. The fun thing is that packed and unpacked structs behave differently - i.e. one reverses, the other doesn't.
    Hopefully one of the simulator gurus can explain.
    If I can find the original explanation from a couple of years ago, I'll post that too...


    Originally posted in cdnusers.org by stephenh
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
No Data

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information