Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!uwm.edu!linac!att!ucbvax!dog.ee.lbl.gov!elf.ee.lbl.gov!torek From: torek@elf.ee.lbl.gov (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Initializing a pointer inside a struct Message-ID: <12166@dog.ee.lbl.gov> Date: 17 Apr 91 16:15:51 GMT References: <1991Apr17.105139.16331@fy.chalmers.se> Reply-To: torek@elf.ee.lbl.gov (Chris Torek) Organization: Lawrence Berkeley Laboratory, Berkeley Lines: 43 X-Local-Date: Wed, 17 Apr 91 09:15:51 PDT In article <1991Apr17.105139.16331@fy.chalmers.se> f90angu@fy.chalmers.se (Andreas Gunnarsson) writes: >I've tried this: > >struct { > ... > int *int_list; > ... >} list_of_structs[] = >{ > { ..., {1, 2, 3, -1}, ...}, > { ..., {4, -1}, ...}, > ... >}; > >It doesn't work. I know I could declare the lists of integers as separate >variables and use the address, but it would be much harder to see what data >belongs where, and I would have to use *lots* of variable names. This is pretty much the only way to do it. >I could also write 'int int_list[MAX];' instead of 'int *int_list;', but in >that case lots of space would be wasted if there is big variance in length. Right. >Is there any simple way to do it? Use a preprocessor (not `cpp'); have it emit something like int L0[] = { 1, 2, 3, -1 }; int L1[] = { 4, -1 }; ... struct ... list_of_structs[] = { { ..., L0, ... }, { ..., L1, ... }, ... }; where each Li is the array to which list_of_structs[i] should point. -- In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 415 486 5427) Berkeley, CA Domain: torek@ee.lbl.gov