"Empty structure" warning

In a template, creating a struct that contains only local variables causes the message *WARNING: Line xxx: Empty Structure. Doing so iteratively can produce the message many times, potentially leading to the warning Too many warnings to display. .

Yet such “empty” structs can be useful when defining two or more very similar structs, or variants of the same struct, where one or more versions of the struct have a field that corresponds to certain data present in the data file, while at least one version has a different type of data (or no data) in the file.

There are probably several other ways to achieve the result that I want, but I’ve found
I hope the very simplified example below, while not doing anything useful itself, will get across what I’m doing, even if I’ve made a mistake in typing it “on the fly”. (I don’t have the actual code handy on this system.)

typedef struct {
	unsigned byte length;
	if ( s > 0 ) {
		char s[length];
		local string text = SubStr( s, 0, length );
	}
	else {
		local string text = "missing text";
	}
} countedString;

typedef struct {
	uword number;
	local string text = Str( "%u", lineNumber );
} lineNumber;

typedef struct {
    byte type;
    if ( type == 1 )
		countedString symbol;
	else if ( type == 2 )
		lineNumber symbol;
} DebugSymbol < name=debugSymbolStr >;

string debugSymbolStr( debugSymbol &s )
{
	return s.text;
}

DebugSymbol symbolTable[100];

I’d like to suggest a new feature that would allow the deliberate creation of “empty” structs without the warning message.

I can think of several syntaxes for doing so. My ideas are below, but of course you can use whatever syntax seems best to you.

  1. A pseudo-function, perhaps void EmptyStruct(void)
  2. A preprocessor directive (perhaps a #pragma emptystruct)
  3. A special empty=true|false attribute for structs.

For #1, the end of the empty scope of the might be explicitly indicated with a corresponding NoEmptyStruct(), or for #2, with #pragma noemptystruct.

For #3, the scope would implicitly be the entire struct. (Raising the question of what to do with sub-structs).

I’m very interested to hear your thoughts.

There is already a way to turn off the warning for empty structs. On the ‘Compiling’ page in the Options dialog, to the right of the ‘Show Warnings’ toggle click the ‘Configure’ button and turn off ‘Empty structure/union’. Cheers!

Graeme
SweetScape Software

I had forgotten about the setting you mentioned. Thanks for reminding me.

But I do think a finer-grained approach to empty structs might be helpful when you want to have deliberately empty structs but still get warnings for structs that you haven’t explicitly defined as empty.

I can certainly understand if you prefer not to spend time working on a more flexible approach (or at least not not yet) just for the convenience of a single customer. :slight_smile: But I hope you will (or already have) give it at least some consideration.

Yes, have a finer grained control could be useful. We were thinking about adding a <warn=false> attribute that could be used for zero-sized structs but could also be used for zero-sized arrays as well. Cheers!

Graeme
SweetScape Software