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

lib: utilities: add MB and GB defines #249

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ extern "C" {
* @{
*/

#define MB (1024 * 1024UL)
#define GB (1024 * 1024 * 1024UL)
#ifndef MB
#define MB (1024UL << 10UL)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arnopo

I have question here. Since MB and GB are so common terms, should we check values compile time of MB and GB if they are defined somewhere else ?

For example:

#ifndef MB
...
#else

#if (MB != (1024 * 1024))
#error "error: unexpected value of MB"
#endif

something like this? Since MB can be defined as 1000 * 1000.

I am asking since want to know if it's overkill and we can simply assume that everywhere it will be defined as 1024 * 1024.

Thanks,
Tanmay

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me we can assume that MB is defined as 1024 *1024.

#endif

#ifndef GB
#define GB (MB << 10UL)
#endif

/** Marker for unused function arguments/variables. */
#define metal_unused(x) do { (x) = (x); } while (0)
Expand Down