Type inconsistency

A user interface toolkit mainly for audio plug-ins (VST, AudioUnit, etc).
Post Reply
User avatar
pongasoft
Posts: 89
Joined: Sun Mar 11, 2018 5:57 pm
Location: Las Vegas, USA
Contact:

Type inconsistency

Post by pongasoft » Thu Oct 03, 2019 3:11 pm

In the VST SDK, ParamID is defined to be uint32

Code: Select all

typedef uint32 ParamID;			///< parameter identifier
uint32 is then defined this way

Code: Select all

#if SMTG_OS_WINDOWS && !defined(__GNUC__)
	typedef long int32;
	typedef unsigned long uint32;
#else
	typedef int int32;
	typedef unsigned int uint32;
#endif
In VSTGUI, ccontrol.h defines this:

Code: Select all

virtual void setTag (int32_t val);
virtual int32_t getTag () const { return tag; }
And so it uses int32_t which on Windows is defined to be int... which is not a long (like int32 is mapped to be).

Shouldn't this API uses int32 instead of int32_t? Is this a bug or is there a very specific rationale for this usage?

Thanks
Yan

Arne Scheffler
Posts: 304
Joined: Mon Jun 20, 2016 7:53 am

Re: Type inconsistency

Post by Arne Scheffler » Fri Oct 04, 2019 3:23 pm

Hi,
VSTGUI is a separate module with no dependency to the VST SDK. That's why some things are different.
Do you have any specific problem with this ?

Cheers,
Arne

User avatar
pongasoft
Posts: 89
Joined: Sun Mar 11, 2018 5:57 pm
Location: Las Vegas, USA
Contact:

Re: Type inconsistency

Post by pongasoft » Fri Oct 04, 2019 6:39 pm

I actually did. It is not a showstopper problem since I was able to work around it but yet it is a problem:

I ended up writing some generic code to create some parameters (in my framework), with APIs like those:

Code: Select all

template<typename T>
GUIParam<T> registerParam(ParamID iParamID); // ParamID == uint32

template<typename T>
GUIParam<T> registerParam(TagID iTagID) { // TagID == int32
  if(iTagID < 0)
    return {};
  else
   return registerParam<T>(static_cast<ParamID>(iTagID));
} 

And then in a view (which inherits from CControl) I end up writing:

Code: Select all

void registerParameters() {
  fMyParam = registerParam<T>(getTag());
}

And this code worked fine with macOS/XCode but failed on Windows / Visual Studio Build tools with an error telling me that the call was ambiguous. I can fix the issue by doing:

Code: Select all

void registerParameters() {
  fMyParam = registerParam<T>(static_cast<TagID>(getTag()));
}
but that made me realize that there was an inconsistency between the types (on Windows) since int32_t and int32 are NOT the same type. I wished I didn't have to explicitly cast the tag since it doesn't seem right to me because it should represent the same type as used in the VST world... It also took me a long time to realize what the actual problem was (especially when dealing with templated code and error messages that are not very friendly). I am sure other people will bump into similar issues one day or another.

Post Reply