Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!dali.cs.montana.edu!uakari.primate.wisc.edu!sdd.hp.com!mips!pacbell.com!att!linac!unixhub!ditka!comeau From: comeau@ditka.Chicago.COM (Greg Comeau) Newsgroups: comp.sys.amiga.programmer Subject: Re: Dynamic struct's Message-ID: <38578@ditka.Chicago.COM> Date: 10 May 91 14:23:36 GMT References: <52955@nigel.ee.udel.edu> Sender: comeau@ditka.Chicago.COM (Greg Comeau) Reply-To: comeau@csanta.attmail.com (Greg Comeau) Organization: Comeau Computing Lines: 21 In article <52955@nigel.ee.udel.edu> DA3721A@acad.drake.edu writes: >My question is: How does one dynamically declare a struct >for accessing the correct number of fields? In other words, rather than doing > struct { int field1; char field2; int field3; } record; >I would like to do something like > struct { int field1; char field2; ... int fieldx;} record; There is no direct language support for this in C. However alternates can range from your writing out C code with the new structure, compiling it, and access routines to it, and throwing them into a dynamic/share library, to building the structure fully in a dynamic manne with things like malloc() and an array of structures (continaing info like: field name, type of field, field length, field alignment requirements, etc). Neither is really an attractive choice. - Greg -- Comeau Computing, 91-34 120th Street, Richmond Hill, NY, 11418 Producers of Comeau C++ 2.1 Here:attmail.com!csanta!comeau / BIX:comeau / CIS:72331,3421 Voice:718-945-0009 / Fax:718-441-2310