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

Use more macros #21

Open
ElDeveloper opened this issue Aug 17, 2017 · 0 comments
Open

Use more macros #21

ElDeveloper opened this issue Aug 17, 2017 · 0 comments

Comments

@ElDeveloper
Copy link
Member

In #18 and maybe elswhere there's a few patterns that could be abstracted into a few macros, for example

if(obs_indices_resident == NULL) {
    fprintf(stderr, "Failed to allocate %zd bytes; [%s]:%d\n", 
            sizeof(uint32_t**) * n_obs, __FILE__, __LINE__);
    exit(EXIT_FAILURE);
}

To something like:

#define fail_if_null(mem, size) {\
 if (mem == NULL) { \
     fprintf(stderr, "Failed to allocate %zd bytes; [%s]:%d\n",\
             size, __FILE__, __LINE__);\
     exit(EXIT_FAILURE);\
 } \
}

So all these lines turn into:

fail_if_null(obs_indices_resident, sizeof(uint32_t**) * n_obs);

disclaimer: my C is a bit rusty and I haven't checked that the code above compiles.

@ElDeveloper ElDeveloper mentioned this issue Aug 17, 2017
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

1 participant