# PAssing array of structures from C to SV

**URL:** <https://verificationacademy.com/forums/t/passing-array-of-structures-from-c-to-sv/36151>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, DPI\
**Created:** [June 5, 2019, 7:36pm UTC](https://verificationacademy.com/forums/t/passing-array-of-structures-from-c-to-sv/36151 "2019-06-05T19:36:57Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [June 5, 2019, 8:56pm UTC](https://verificationacademy.com/forums/t/passing-array-of-structures-from-c-to-sv/36151/2 "2019-06-05T20:56:50Z")

</div>

_In reply to [superUVM](https://verificationacademy.com/forums/t/passing-array-of-structures-from-c-to-sv/36151):_

SystemVerilog code:

```verilog
module top;
   typedef struct {int A; byte B; int C; } my_struct_t;
   typedef my_struct_t my_struct_array_t[2];
   import "DPI-C" function void pass_struct(output my_struct_array_t a);

   my_struct_array_t SA;

   initial begin
      pass_struct(SA);
      $display("%p",SA);
   end
endmodule // top

```

C code:

```auto
#include "dpicstruct.h"

void pass_struct( my_struct_t* a) {
  int i=0;
  a[0].A = i++;
  a[0].B = i++;
  a[0].C = i++;
  a[1].A = i++;
  a[1].B = i++;
  a[1].C = i++;
}

```

dpicstruct.h (generated automatically)

```auto
/ * Copyright 2002-2019 Mentor Graphics Corporation.
 *
 * Note:
 * This file is automatically generated.
 * Please do not edit this file - you will lose your edits.
 *
 * Settings when this file was generated:
 * PLATFORM = 'linux_x86_64'
 */
#include "svdpi.h"
typedef struct {
    int A;
    char B;
    int C;
} my_struct_t;

void
pass_struct(
    my_struct_t* a);

```

Displays:

```auto
# '{'{A:0, B:1, C:2}, '{A:3, B:4, C:5}}

```

---

_[View the full topic](https://verificationacademy.com/forums/t/passing-array-of-structures-from-c-to-sv/36151)._
