Skip to content
This repository was archived by the owner on Apr 24, 2019. It is now read-only.

Change uint8_t bitfields to int #100

Merged
merged 1 commit into from
Dec 12, 2016

Conversation

kuggenhoffen
Copy link
Contributor

In c ISO 1990 bitfields can be only int

@kuggenhoffen
Copy link
Contributor Author

Copy link
Contributor

@kjbracey kjbracey left a comment

Choose a reason for hiding this comment

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

Comment nit - we're actually doing C99, not C90. Standard types are unsigned int, signed int and bool.

But the main thing is "never just int".

@@ -146,7 +146,7 @@ typedef struct sn_nsdl_static_resource_parameters_ {
uint16_t resourcelen; /**< 0 if dynamic resource, resource information in static resource */
bool external_memory_block:1; /**< 0 means block messages are handled inside this library,
otherwise block messages are passed to application */
uint8_t mode:2; /**< STATIC etc.. */
int mode:2; /**< STATIC etc.. */
Copy link
Contributor

Choose a reason for hiding this comment

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

Never use "int" bitfields. It's undefined whether they're signed or unsigned. Always make them explicitly "signed" or "unsigned" (you can then leave out the "int").

GCC and ARMCC do actually have different behaviour on this - been bitten by that before.

@TeroJaasko
Copy link
Contributor

If I am not remembering it wrong, the sign of a int in bitfield is implementation specific. It would be better to use "unsigned int".

@kuggenhoffen kuggenhoffen merged commit 622f88d into memory_optimizations Dec 12, 2016
TeroJaasko pushed a commit that referenced this pull request Dec 14, 2016
Use unsigned int for bitfields for C99 compliance
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants