Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing bit-field in C by its address

What is the reason behind not allowing to access a bit field in C using its address, is it cause it might not be an address that is not system word aligned ..? or as it doesn't make sense to get bit's address within a byte...?(cause this types pointer arithmetic will be awkward ?)

like image 680
Vijay Avatar asked Jan 28 '26 06:01

Vijay


2 Answers

Bits do not have addresses. That's why you can't refer to them by address. The granularity of addressing is the char.

I guess the reasoning is that the language was design to match the architecture it targeted, and I know of no machine which allows addressing of individual bits.

like image 157
David Heffernan Avatar answered Jan 30 '26 19:01

David Heffernan


The smallest unit of addressable memory in C is a char, because this corresponds to the smallest unit of addressable memory on most CPU architectures.* It doesn't make sense to talk about the address of a bit.


* One could imagine a hypothetical machine that allowed addressing of individual bits, but it would be pretty esoteric.
like image 21
Oliver Charlesworth Avatar answered Jan 30 '26 19:01

Oliver Charlesworth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!