Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

The C++ standard doesn't guarantee doesn't guarantee that a long is 4 bytes — it may be longer. If you want 8 nibbles, then make number an int32_t. If you want to split a long into however many nibbles it takes, then use 2 * sizeof number instead of 8.

Long decimal literals should have an L suffix: long int number = 432214123L;

It's fine to use a static array, but you should clearly document that fact in a comment. Also be aware that returning static values makes the design non-reentrant, i.e. not thread-safe. While you are at it, your comment should also mention that the results are least-significant-nibble first.

The C++ standard doesn't guarantee that a long is 4 bytes — it may be longer. If you want 8 nibbles, then make number an int32_t. If you want to split a long into however many nibbles it takes, then use 2 * sizeof number instead of 8.

Long decimal literals should have an L suffix: long int number = 432214123L;

It's fine to use a static array, but you should clearly document that fact in a comment. Also be aware that returning static values makes the design non-reentrant, i.e. not thread-safe. While you are at it, your comment should also mention that the results are least-significant-nibble first.

The C++ standard doesn't guarantee that a long is 4 bytes — it may be longer. If you want 8 nibbles, then make number an int32_t. If you want to split a long into however many nibbles it takes, then use 2 * sizeof number instead of 8.

Long decimal literals should have an L suffix: long int number = 432214123L;

It's fine to use a static array, but you should clearly document that fact in a comment. Also be aware that returning static values makes the design non-reentrant, i.e. not thread-safe. While you are at it, your comment should also mention that the results are least-significant-nibble first.

Source Link
200_success
  • 145.6k
  • 22
  • 190
  • 479

The C++ standard doesn't guarantee that a long is 4 bytes — it may be longer. If you want 8 nibbles, then make number an int32_t. If you want to split a long into however many nibbles it takes, then use 2 * sizeof number instead of 8.

Long decimal literals should have an L suffix: long int number = 432214123L;

It's fine to use a static array, but you should clearly document that fact in a comment. Also be aware that returning static values makes the design non-reentrant, i.e. not thread-safe. While you are at it, your comment should also mention that the results are least-significant-nibble first.

lang-cpp

AltStyle によって変換されたページ (->オリジナル) /