-
Notifications
You must be signed in to change notification settings - Fork 456
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
Bit fields type #805
Bit fields type #805
Conversation
The definition of bit-fields with type OPJ_UINT32 caused complilation errors on IBM iSeries, because OPJ_UINT32 is defined as uint32_t, and uint32_t is defined as unsigned long in <stdint.h>. The definition of bit-fields with an integer type of a specific size doesn't make sense anyway.
@@ -129,6 +129,8 @@ typedef uint64_t OPJ_UINT64; | |||
|
|||
typedef int64_t OPJ_OFF_T; /* 64-bit file offset type */ | |||
|
|||
typedef unsigned int OPJ_BITFIELD; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type is only used by internal headers. Please do not define it in openjpeg public header.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mayeut: What would be the right place then? Would it be in opj_includes.h?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@smuehlst , yes opj_includes.h
seems to be the right place for this.
Why is a new type needed? I'd simply use |
I forgot |
I also forgot to mention that |
@stweil: I just tried to follow the convention that OpenJPEG uses OPJ_ typedefs for all the basic types. Therefore it seemed to make sense to me to introduce a new type OPJ_BITFIELD. The additional benefit is that if there ever is an exotic compiler that has problems with the given definition of OPJ_BITFIELD, the type to use for bit-fields can be changed in a central place. |
OpenJPEG also uses lots of |
I must correct myself: The C standard does not allow enums for bit fields:
Enum types are supported for bit fields in C++:
|
I think that having a type @detonin for feedback |
Instead of |
Yes I know but some don't... that's why I always use |
OPJ_BITFIELD is used only in internal headers and must not appear in the public openjpeg.h header.
I moved the definition of OPJ_BITFIELD from openjpeg.h to opj_includes.h. |
I think it's a good idea to make immediately clear what type of variable is expected so I think OPJ_BITFIELD is good, and it actually does not harm. But defining it in opj_includes.h seems a bit weird to me (although I agree that if it's an internal type it should not modify openjpeg.h). Maybe we should at least define a new section in opj_includes.h with "Internal types" or sth like this. Comments ? |
I agree that replacing |
@stweil, as you mention, all bitfields are used for boolean values in the code.
with only one |
As the current code already uses |
The only files were
Well,
The file
As you stated, the underlying type for
Well, I agree with the general idea however compatibility with C89 is mandatory... That's why I proposed the mixed approach to define OPJ_BOOL_BITFIELD given that CI jobs will check that both paths are executed the same way. Use proper standard if available, else use "wrong" type (we're still in the early years of C programming...). The whole being seen as a ugly hack. |
Thanks for that update. It is indeed different for C and C++. While gcc fails to compile |
@mayeut: Do I understand it correctly that the current code with OPJ_BITFIELD is "good enough" for the moment, or are additional changes necessary before the pull request will be accepted? |
@smuehlst I suggest we merge this as is. |
The definition of bit-fields with type OPJ_UINT32 caused compilation errors
on IBM iSeries, because OPJ_UINT32 is defined as uint32_t, and
uint32_t is defined as unsigned long in
<stdint.h>
on IBM iSeries:The definition of bit-fields with an integer type of a specific size doesn't make sense anyway. Therefore I introduced a new typedef
OPJ_BITFIELD
defined asunsigned int
, and changed all bit-fields in structures to use this typedef.