Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev-ooi: AdsClient.h does not compile with Visual Studio 2015 #38

Closed
pbruenn opened this issue Sep 19, 2016 · 5 comments
Closed

dev-ooi: AdsClient.h does not compile with Visual Studio 2015 #38

pbruenn opened this issue Sep 19, 2016 · 5 comments

Comments

@pbruenn
Copy link
Member

pbruenn commented Sep 19, 2016

moved from #35:
xift wrote:
Sidenote: AdsClient.h does not compile with Visual Studio 2015.
It doesn't like the HandleGuard.

return AdsHandleGuard {new uint32_t {handle}, std::bind(&ReleaseHandle, address, port, std::placeholders::_1)};

No instance of constructor "std::unique_ptr<_Ty, _Dx>::unique_ptr [with _Ty=uint32_t, _Dx=std::_Binder &>]" matches the argument list.
Argument types are: (uint32_t , std::_Binder<std::_Unforced, void ()(AmsAddr address, long port, uint32_t *handle), const AmsAddr &, long &, const std::_Ph<1> &>)
You seem to be quite familiar with modern C++. Do you often use ? I know what bind does but I have never had the opportunity to use it. I just don't think about that. How did you start using it?

@pbruenn
Copy link
Member Author

pbruenn commented Sep 19, 2016

I will take a look on this one later. Maybe VC++ is missing some c++11 feature or my knowledge is smaller than you think and gcc is just doing magic with my code ;-).
Some years ago I attended "ESE Kongress" in Sindelfingen. The lecture of Prof. Peter Sommerlad opened my mind for C++11 and simple code. So I started to take a deeper look into STL and always try solve my problems using standard C++ library mechanisms.
Funny fact: he told me at the coffee table destructors are evil. At that time I didn't really understand what he meant. But now I "think" I figured out it is because of the "rule of five", so I try to implement "rule of zero".
At least AdsHandleGuard is my try to implement it. Comments and laughter of experts would be appreciated ;-).

Regards,
Patrick

@mwiarda
Copy link
Contributor

mwiarda commented Sep 19, 2016

The ironic thing is that what prevents me from using the STL in my daily work is the limited subset of the STL that is supported by TwinCAT 3.1 C++ modules :-)
I try to keep myself up to date by listening to conference talks and reading a lot.
Whenever I work on a "non-kernel-mode" sideproject I test out everything I learned.

That rule of zero thing is a really clever idea. I already admired that solution in your code 👍
Its beautiful - but it is not obvious. I like code to be straightforward and easy to read. This solution is neat but can throw off people quickly. You always stop to wonder if it really covers any remote case that can happen. Anyway, it probably outperforms any constructor/destructor/... implementation I could write.

I guess you are right with the rule of five idea. And then there is the "throwing in destructors"-problem and the issue with destructors of base classes.

Regards,
Michael

@pbruenn
Copy link
Member Author

pbruenn commented Sep 20, 2016

😆 I will try to convince my colleagues of c++14 support in TwinCAT at the lunch table ;-).

I prefer easy to read code, too. But that lecture encouraged me "learn to master the tools you use".
In every profession you have to learn to handle your tools. Only in programming some guidelines force you to write stuff like this:

if (0 == error) {
    do_error_handling(error);
} else {
    // this is empty to be compliant with coding guideline...
}

Just to make sure anyone could read it. No one would tell a carpenter to always use a handsaw just because a circular saw will cut his finger faster.

@mwiarda
Copy link
Contributor

mwiarda commented Sep 20, 2016 via email

@pbruenn
Copy link
Member Author

pbruenn commented Sep 21, 2016

I am absolutely with you. "Clever coding" is as stupid as "Clever cable handling". However if you want to be allowed to handle cables, you have_to learn the cable codings.

In commit a4f2064 you can see even clever "rule of zero" has its pitfalls ;-).

I still think there is some error in VC++2015 std::bind/placeholders/std::unique_ptr implementation. This article sounds promising but even with VS2015 Update 3 I got the same error so I rewrote AdsHandle in commit b1d306e

@pbruenn pbruenn closed this as completed Sep 21, 2016
mwiarda pushed a commit to mwiarda/ADS that referenced this issue Oct 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants