🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #51634

arrays of variable length

#51634
From: Marty Leisner x71348
Date: Tue, 27 Apr 1993 14:54
39 lines
1490 bytes
I want to use arrays of variable length.

I want to do something like:
#ifdef __GNUC__
typedef struct {
	int size;
	char mess[0];
} SMALL_MESSAGE;
#endif

#define MAX_MESSAGE 128
typedef struct {
	int size;
	char mess[MAX_MESSAGE]
} BIG_MESSAGE;

The problem is prototypes...how do I define a prototype which reads either message...

i.e.

read_message(SMALL_MESSAGE *) and
read_message(BIG_MESSAGE *)

If I'm going to not use memory allocation routines, I want to just do:
	func()
	{
		BIG_MESSAGE mess;

		mess.size = MAX_MESSAGE;

If I'm using memory allocation routines, I can be cleverer.

How to I get around this problem?

--
Marty Leisner	leisner@eso.mc.xerox.com   leisner.henr801c@xerox.com
"To write poetry after Auschwitz is barbaric"
        German philosopher Theodor Adorno
Technical Details
Message-ID: <1993Apr27.145459.29598@spectrum.xerox.com>
Path: arc1-ca.pugleaf.net!gmd.de!ira.uka.de!howland.reston.ans.net!zaphod.mps.ohio-state.edu!sdd.hp.com!caen!batcomputer!cornell!rochester!rocksanne!leisner

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,8caa791f63fe73f6,start
X-Google-Attributes: gid11318c,public
X-Google-ArrivalTime: 1993-04-27 17:57:42 PST
Newsgroups: gnu.gcc.help
Path: arc1-ca.pugleaf.net!gmd.de!ira.uka.de!howland.reston.ans.net!zaphod.mps.ohio-state.edu!sdd.hp.com!caen!batcomputer!cornell!rochester!rocksanne!leisner
From: leisner@wrc.xerox.com (Marty Leisner x71348 )
Subject: arrays of variable length
Message-ID: <1993Apr27.145459.29598@spectrum.xerox.com>
Sender: news@spectrum.xerox.com
Reply-To: leisner@eso.mc.xerox.com
Organization: Xerox
X-Newsreader: TIN [version 1.1 PL9]
Date: Tue, 27 Apr 1993 14:54:59 GMT
Lines: 40