-
Notifications
You must be signed in to change notification settings - Fork 197
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
Replace memcpy and memcmp with assignement and compare operators #119
Conversation
@@ -245,15 +245,26 @@ struct AmsNetId { | |||
/** NetId, consisting of 6 digits. */ | |||
uint8_t b[6]; | |||
|
|||
#ifdef __cplusplus |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a public header, which should be usable in pure C projects. Without this guard a C compiler will complain.
AdsLib/AdsDef.cpp
Outdated
} | ||
} | ||
return false; | ||
static const AmsNetId empty {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mixed usage of tab and spaces for indentation. Please replace all instances of tabs (there are other lines too) with 4 spaces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have an uncrustify config for this:
https://github.com/Beckhoff/ADS/blob/master/tools/uncrustify.cfg
make uncrustify
AdsLib/Router.h
Outdated
@@ -26,6 +26,8 @@ | |||
#include "AdsDef.h" | |||
|
|||
struct Router { | |||
virtual ~Router() {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there is a need to explicitly add a destructor here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing destructor causes warnings in Eclipse, but I will remove it.
AdsLib/AdsDef.cpp
Outdated
} | ||
|
||
|
||
bool AmsNetId::operator == (const AmsNetId& rhs) const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bool AmsNetId::operator == (const AmsNetId& rhs) const | |
bool AmsNetId::operator==(const AmsNetId& rhs) const |
... also for the other operators
Hi pogojotz. I followed your suggestions and updated my pull request. |
This merge request is hard to read, please squash your updates, if they are fixes only. |
The reason for my pull request was to avoid using memcpy on class pointers, see changes in file AmsRouter.cpp (line 116):
My pull request "Replace memcpy and memcmp with assignement and compare operators" is suggesting a fix by using assignment operators to copy the class/struct member "uint8_t b[6];" content. |
I still don't see the reason or benefit. You are adding more than 40 lines of code to replace one call of memcpy with an assignment? AmsRouter::localAddr is a struct AmsNetId, which itself is just an alias for an uint8_t[6]. It has no vtable so sizeof(struct AmsNetId) is just the same as sizeof(uint8_t[6]). |
I believe the code will/might work, as long as the C-style struct does contain native C variable types like the given uint8_t[6] and as long as both objects are persistent. By copying the whole struct (class) content by using memcpy on the object pointers, also the C++ member function pointers are copied from one object to the other. This leads to the situation that the copied object is accessing (or lets say is working) with the member methods of the original object. |
I think clean depends on the view. I my view it's a big patch (4 files changed, 70 insertions(+), 14 deletions(-)) fixing a theoretical issue. AmsNetId is part of the ADS C API so I am pretty sure it won't get any vtables. |
Hmm, hard to comment... |
Replace memcpy and memcmp with assignement and compare operators in class AmsNetId.