-
Notifications
You must be signed in to change notification settings - Fork 1
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
Boilerplate #1
base: master
Are you sure you want to change the base?
Boilerplate #1
Conversation
add newlines at end of files |
break header files into header (only function signatures/declarations) and cpp files for logic (function definitions) |
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.
very well drafted PR. Awesome work!!
// Similar to ferror() and clearerr() | ||
|
||
virtual bool err() const { return false; } | ||
virtual void clearError() {} |
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.
make this a purely virtual function
typedef unsigned char byte; | ||
typedef unsigned char uint8; | ||
typedef signed char int8; | ||
typedef unsigned short uint16; | ||
typedef signed short int16; | ||
typedef unsigned int uint32; | ||
typedef signed int int32; | ||
typedef unsigned int uint; | ||
typedef signed long long int64; | ||
typedef unsigned long long uint64; |
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.
kinda risky, use https://cplusplus.com/reference/cstdint/ for full portability
inline uint16 READ_UINT16(const void *ptr) { | ||
const uint8 *b = (const uint8 *)ptr; | ||
return (b[1] << 8) | b[0]; | ||
} |
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.
if you're writing for little endian, why not do:
inline uint16 READ_UINT16(const void *ptr) {
const uint16 *b = (const uint16 *)ptr;
return *b;
}
you can even do this
template<typename T>
static inline T READ(const void *ptr) {
const uint16 *b = (const uint16 *)ptr;
return *b;
}
// And if you don't want to use READ<uint32> everywhere:
static inline uint32 READ_UINT32(const void *ptr) {
return READ<uint32>(ptr);
}
...
(try using static inline as much as you can)
Also please avoid using void*
in cpp, typedef or string typedef to signify that this is a stream.
Using constexprs you can even write a common definition for loading LE values on a BE and LE system:
template<typename T>
constexpr static inline T READ(const void *ptr) {
// set isBigEnding somewhere using constexpers to detect
if constexpr (isBigEndian) {
constexpr size_t byteCount = sizeof(T);
T res = 0;
// This will be unrolled easily
for(size_t i = byteCount - 1; i >= 0; i-- ) {
res |= (((T*)ptr)[i] << (i * 8));
}
return res;
}
else {
const uint16 *b = (const uint16 *)ptr;
return *b;
}
}
^ This can very easily be extended to get support BE values on a BE and LE system as well with a couple of more if branches and is pretty idiomatic.
@@ -0,0 +1,99 @@ | |||
#include "emusys.h" |
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.
in general, try to use constexpr
as much as possible and macros as a last resort, you can even use constexpr
to determine if the platform is big endian or little endian at compiletime
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu | ||
// Debug program: F5 or Debug > Start Debugging menu | ||
|
||
// Tips for Getting Started: | ||
// 1. Use the Solution Explorer window to add/manage files | ||
// 2. Use the Team Explorer window to connect to source control | ||
// 3. Use the Output window to see build output and other messages | ||
// 4. Use the Error List window to view errors | ||
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project | ||
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file |
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.
remove kek
No description provided.