• 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. Custom IC SKILL
  3. how to create a table/list of structs

Stats

  • Locked Locked
  • Replies 6
  • Subscribers 143
  • Views 5548
  • 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

how to create a table/list of structs

NcfC
NcfC over 6 years ago

Hi,

I'm trying to create a struct variable,

defstruct( name field1 field2 ...)

struct_var = name

and then have a table/list where each element is a name struct. For example,

struct_var[1]->field1 = "1"

struct_var[1]->field2 = "11"

struct_var[2]->field1 = "2"

struct_var[2]->field2 = "22", and so on.

But it seems that I cannot create of table/list of name elements!

Could anyone help me?

Thanks in advance.

Best regards,

  • Cancel
Parents
  • mbracht
    mbracht over 6 years ago

    Not sure whether I really understand what you'r up to but...the defstruct statement only defines a template for a structure, to actually allocate memory for an instance of that template you need to call make_<structName>:

    defstruct(person name age)
    person1=(make_person)

    So the above defstruct statement "creates" the make_person() command. And again - the array that is created (name in your example) just serves as a template that is used during make_name().

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • NcfC
    NcfC over 6 years ago in reply to mbracht

    hi, mbracht.

    thanks for the promptly reply.

    Sorry for the confusion.

    What I would like to to do is to create a table/list in which each element of the table/list is of the type name (a struct).

    Thanks again.

    Best regards,

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • mbracht
    mbracht over 6 years ago in reply to NcfC

    (defstruct person first last age)
    tbl=(makeTable 'myTable)
    tbl[0] = (make_person ?first "Jim" ?last "Morrison" ?age 27)
    tbl[1] = (make_person ?first "Janis" ?last "Joplin" ?age 27)
    (println tbl[1]->first)    ;  <-- that should print 'Janis'

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • mbracht
    mbracht over 6 years ago in reply to NcfC

    (defstruct person first last age)
    tbl=(makeTable 'myTable)
    tbl[0] = (make_person ?first "Jim" ?last "Morrison" ?age 27)
    tbl[1] = (make_person ?first "Janis" ?last "Joplin" ?age 27)
    (println tbl[1]->first)    ;  <-- that should print 'Janis'

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
  • NcfC
    NcfC over 6 years ago in reply to mbracht

    Hi, mbracht.

    using make_person worked very well, thanks. But why I cannot use tbl[0]->first = "Jim" instead? If I use

    tbl[0]->first = "Jim"

    tbl[0]->last = "Morrison"

    tbl[1]->first = "Janis"

    tbl[1]->last = "Joplin"

    I get,

    ocean> tbl[1]->first
    "Janis"
    ocean> tbl[0]->first
    "Janis"

    Best regards,

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • mbracht
    mbracht over 6 years ago in reply to NcfC

    Like I said you need to allocate the memory for a structure which only make_<structName> does.
    What happens in the tbl[0]->first statement is that
    1) tbl[0] is evaluated
    2) the arrow operation ->first is applied to whatever tbl[0] evaluates to.
    Now unless you do tbl[0]=make_person(..). tbl[0] will return the unbound symbol. So you apply the arrow operation to unbound which is syntactically correct but not what you want. What you really want is to apply ->first to a structure of type person so make sure tbl[0] is a structure of type person.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • NcfC
    NcfC over 6 years ago in reply to mbracht

    Oh, OK. It makes sense!

    thanks very much.

    best regards

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

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