OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 7:17 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Thoughts on enum types and bit packing
PostPosted: Tue Jun 23, 2020 5:06 pm 
Offline

Joined: Thu Jul 18, 2013 3:48 am
Posts: 2
So I want other people's opinions on a couple of programming practices I've been using on and off.
First using enum types (in C) to define multiple constants in a group, for example creating a enum type for GDT flags bitmasks.
I know I'm making a type for these constants that I never actually use but should I just convert this into a series of #defines?

And then if I use bit packed structs to make bitmasks using bool types for values that don't have a particular location ie a set of flags for my own implementation of driver management, would I have to worry about different compilers putting bits in different orders?


Top
 Profile  
 
 Post subject: Re: Thoughts on enum types and bit packing
PostPosted: Tue Jun 23, 2020 7:53 pm 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 1593
pANZERNOOb wrote:
So I want other people's opinions on a couple of programming practices I've been using on and off.
First using enum types (in C) to define multiple constants in a group, for example creating a enum type for GDT flags bitmasks.
I know I'm making a type for these constants that I never actually use but should I just convert this into a series of #defines?
The two are equivalent in most cases. Only difference is, macros can be used in #if. Otherwise there is not much of a difference.

pANZERNOOb wrote:
And then if I use bit packed structs to make bitmasks using bool types for values that don't have a particular location ie a set of flags for my own implementation of driver management, would I have to worry about different compilers putting bits in different orders?
If all compilers follow the same ABI, or at least all ABIs say the same about bitfields, or you only ever compile the entire project with one compiler at a time, there is nothing to worry about. You should start worrying when you want to transmit such a structure somewhere, whether into shared memory, a file, or network.

_________________
Carpe diem!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 45 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group