Asking for nStructSize of known structs

I'm curious why Amibroker asks the plugin for nStructSize for some structs who's fields are all well defined primitives, for example, the PluginInfo only contains 32 bit signed integers and two 64 byte char arrays so it's size will always be 152.

Even on a 64bit machine, the size_of(int) = 4 and only int* are 8 bytes long so curious why we have to provide nStructSize for these cases.

struct PluginInfo
{
	int nStructSize;	// this is sizeof( struct PluginInfo )
	int nType;			// plug-in type currently 1 - indicator is the only one supported
	int nVersion;		// plug-in version coded to int as MAJOR*10000 + MINOR * 100 + RELEASE
	int nIDCode;		// ID code used to uniquely identify the data feed (set it to zero for AFL plugins)
	char szName[64];	// long name of plug-in displayed in the Plugin dialog
	char szVendor[64];	// name of the plug-in vendor
	int nCertificate;	// certificate code - set it to zero for private plug-ins
	int nMinAmiVersion; // minimum required AmiBroker version (should be >= 380000 -> AmiBroker 3.8)
};

Just curious...
Thanks,
Joe

This is known technique of providing backward AND forward binary compatibility.

If struct size is provided to the API function call, then in the future you can EXPAND structure by adding new fields. Thanks to struct size member, the API would know if your client is aware of new API (using new struct size) or not (using old struct size).

Windows itself does the same thing:

and

3 Likes