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

Avoiding conditional directives that split up parts of statements. #1480

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

marciomribeiro
Copy link

A suggestion to compile entire statements and expressions, as suggested by code style guidelines from the Linux Kernel and practitioners.

https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/CodingStyle#n892
https://www.cqse.eu/en/blog/living-in-the-ifdef-hell/

It might improve code understanding, maintainability and error-proneness.

@GrayHatter
Copy link
Collaborator

@marciomribeiro can you indent the #ifdefs as well?

@marciomribeiro
Copy link
Author

I've attached 2 files. Do you prefer Option1 or Option2?

Option 1:
option1

Option 2:
option2

@GrayHatter
Copy link
Collaborator

I like option 2

@marciomribeiro
Copy link
Author

Don't know why the CI build has failed. I didn't change anything but the indentation...

@GrayHatter
Copy link
Collaborator

that's normal, the tests are broken

On Tue, Mar 8, 2016 at 11:24 AM, Márcio Ribeiro notifications@github.com
wrote:

Don't know why the CI build has failed. I didn't change anything but the
indentation...


Reply to this email directly or view it on GitHub
#1480 (comment).

@marciomribeiro
Copy link
Author

Is the pull request now ready to be accepted?!

@GrayHatter
Copy link
Collaborator

once I or someone else can review it yeah! thanks!

@GrayHatter GrayHatter removed their assignment Jul 9, 2016
@GrayHatter
Copy link
Collaborator

@marciomribeiro you may want to reopen this on https://github.com/TokTok/toxcore

@iphydf
Copy link
Contributor

iphydf commented Sep 22, 2016

Is this going to be merged or continued?

@@ -239,12 +239,12 @@ escrypt_kdf_nosse(escrypt_local_t * local,
uint32_t i;

/* Sanity-check parameters. */
#if SIZE_MAX > UINT32_MAX
#if SIZE_MAX > UINT32_MAX
Copy link
Contributor

Choose a reason for hiding this comment

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

@marciomribeiro please undo this formatting change.

if (buflen > (((uint64_t)(1) << 32) - 1) * 32) {
errno = EFBIG;
return -1;
}
#endif
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

And undo this.

#endif
(N > SIZE_MAX / 128 / r)) {
int test = (r > SIZE_MAX / 128 / p) || (N > SIZE_MAX / 128 / r);
#if SIZE_MAX / 256 <= UINT32_MAX
Copy link
Contributor

Choose a reason for hiding this comment

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

Move to column 0.

(r > SIZE_MAX / 256) ||
#endif
(N > SIZE_MAX / 128 / r)) {
int test = (r > SIZE_MAX / 128 / p) || (N > SIZE_MAX / 128 / r);
Copy link
Contributor

Choose a reason for hiding this comment

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

Use _Bool. Also rename to something more useful. test doesn't say anything. What is it testing?

int test = (r > SIZE_MAX / 128 / p) || (N > SIZE_MAX / 128 / r);
#if SIZE_MAX / 256 <= UINT32_MAX
test = test || (r > SIZE_MAX / 256);
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

Move to column 0.

MAP_ANON | MAP_PRIVATE,
#endif
-1, 0)) == MAP_FAILED)
#ifdef MAP_ANON
Copy link
Contributor

Choose a reason for hiding this comment

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

Move all of these back to column 0.

uint32_t i;

/* Sanity-check parameters. */
#if SIZE_MAX > UINT32_MAX
#if SIZE_MAX > UINT32_MAX
Copy link
Contributor

Choose a reason for hiding this comment

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

Same thing in this file: revert the style change.

@marciomribeiro
Copy link
Author

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants