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.
- A pseudo-function, perhaps
void EmptyStruct(void)
- A preprocessor directive (perhaps a
#pragma emptystruct
) - 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.