Sign in to follow this  

__declspec(property) support in GCC 4.x or C++0x?

This topic is 3291 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I know this is a Microsoft specific extension, but I've seen a few cross-platform C++ compilers that support, mainly only the comeau C++ compiler. Does anybody know though if any plugin for GCC or extension provides the __declspec(property) feature? I use Visual Studio as my main compiler but I'm building a cross-platform library that I'd like to use the feature in. And no, I'd rather not resort to designing a custom Property class.

Share this post


Link to post
Share on other sites
Quote:
Original post by soconne
Does anybody know though if any plugin for GCC or extension provides the __declspec(property) feature?


No released version of GCC supports plugins.

No C++ standard (89, 03, 09) supports the concept of properties.

A proposal was recently made to the ISO committee to introduce such a metafacility to the language, but since it was not proposed in time to be accepted into the new standard (released last October) you will need to rely on vendor-specific extensions.

GCC does have the __attribute__((...)) extension, which in many cases performs the same purpose as Microsoft's __declspec(...) extension. I'm not sure exactly what __declspec(property) does, so I can't tell you the gcc equivalent.

Share this post


Link to post
Share on other sites
Quote:
Original post by Bregma
GCC does have the __attribute__((...)) extension, which in many cases performs the same purpose as Microsoft's __declspec(...) extension. I'm not sure exactly what __declspec(property) does, so I can't tell you the gcc equivalent.


It's normally used for exporting/importing DLL funcs. This is largely moot under gcc since you have the -shared flag. It's other uses are primarily for things like memory alignement etc, which you're correct in thinking maps to __attribute__ in gcc

Share this post


Link to post
Share on other sites
Quote:
Original post by Bregma
I'm not sure exactly what __declspec(property) does, so I can't tell you the gcc equivalent.


Its used for creating class properties.


class Test
{
public:
int getvalue() const { return m_value; }
void putvalue(int v) { m_value = v; }

__declspec(property(get=getvalue, put=putvalue)) int value;

private:
int m_value;
};

void main()
{
Test t;
t.value = 10; // executes Test::putvalue method
printf("%i\n", t.value); // executes Test::getvalue method
}



Share this post


Link to post
Share on other sites
Quote:
Original post by soconne
Quote:
Original post by Bregma
I'm not sure exactly what __declspec(property) does, so I can't tell you the gcc equivalent.


Its used for creating class properties.

*** Source Snippet Removed ***

They are pointless an compiler specific, what is wrong with following?

class Test
{
public:
int& value() const { return m_value; }
void value(int const& v) { m_value = v; }
private:
int m_value;
};

int main()
{
Test t;
t.value(10); // executes Test::putvalue method
printf("%i\n", t.value()); // executes Test::getvalue method
}

I know this is just example code but if it were not then I would be asking question about it. Such as the need for a function when they do not preform any validation and are not part of a hierarchy which could preform different operations. In this case the following is good enough

class Test
{
public
int value;
};

Share this post


Link to post
Share on other sites

This topic is 3291 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this