Hi,
I would like to know why array of bitfields is not possible.
Is there any relation with processor architecture for this?
Thank you for your time.
Regards,
Shailendra 19 14801
Mehta Shailendrakumar wrote: Hi,
I would like to know why array of bitfields is not possible. Is there any relation with processor architecture for this? Thank you for your time.
Regards, Shailendra
If the bit is an addressable unit on your implementation,
you may have an array of bitfields.
"Mehta Shailendrakumar " <sh************ *******@de.bosc h.com> wrote:
# Hi,
#
# I would like to know why array of bitfields is not possible.
# Is there any relation with processor architecture for this?
# Thank you for your time.
Because C concentrates on things that are easy to implement in the hardware
and generally leaves harder stuff to libraries rather than implemented
in the syntax. Not many CPUs provide extracting or storing or moving
bit vectors of arbitrary length or orientation. You can do this in your
own code. For example if your CPU allows unaligned access to integers,
32 bit integers and 8 bit bytes,
int getSignedBits(c har *base,int bitoffset,int bitlength) {
assert(bitlengt h<=32);
int *intaddress = base+(bitoffset >>3); // First byte with value.
int value = *intaddress; // Get all of the bits.
value <<= offset & 7; // field sign bit -> int sign.
value >>= 32-bitlength; // field lsb -> int lsb.
return value;
}
--
SM Ryan http://www.rawbw.com/~wyrmwif/
I think that's kinda of personal; I don't think I should answer that. ju**********@ya hoo.co.in wrote: Mehta Shailendrakumar wrote:
Hi,
I would like to know why array of bitfields is not possible. Is there any relation with processor architecture for this? Thank you for your time.
Regards, Shailendra
If the bit is an addressable unit on your implementation, you may have an array of bitfields.
Not in C, you can't.
The problem is that C's array operations are defined
in terms of pointers to the array elements -- a[i] is
defined to be *(a+i), for example. However, a C pointer
cannot point to a bit-field; the "smallest" object a C
pointer can point to is a char. Since it's not possible
to create a pointer to a bit-field, it's not possible to
carry out operations like array indexing that are defined
in terms of pointers.
The underlying hardware may be capable of addressing
individual bits, but C has no way to use that capability.
(The underlying hardware usually has a lot of things C
cannot use: circular shifts, a "carry" flag, memory
protection, vector instructions, hyperthreading, and
so on. C's vocabulary is not rich enough to talk about
such things, so C programs cannot use them.)
--
Eric Sosman es*****@acm-dot-org.invalid
On Fri, 17 Jun 2005 13:39:21 +0200, Mehta Shailendrakumar wrote: Hi,
I would like to know why array of bitfields is not possible.
Because the designers of C decided not to add support for these to the
language. We can try to guess why that is the case, but that is the
fundamental reason.
Is there any relation with processor architecture for this?
Nor really. They would be easier/more efficient to implement on some
architectures than others but they are doable on any architecture that
supports C. That's easy to show because you can write portable C code that
implements them using bit operations on integer types. That is one
possible reason why the designers of C decided that the language didn't
need to support them directly.
Lawrence
Le 17/06/2005 19:09, dans pa************* *************** @netactive.co.u k,
«*Lawrence Kirby*» <lk****@netacti ve.co.uk> a écrit*: On Fri, 17 Jun 2005 13:39:21 +0200, Mehta Shailendrakumar wrote:
Hi,
I would like to know why array of bitfields is not possible.
Because the designers of C decided not to add support for these to the language. We can try to guess why that is the case, but that is the fundamental reason.
That reminds me of MATLAB's "why" command :-) Is there any relation with processor architecture for this?
Nor really. They would be easier/more efficient to implement on some architectures than others but they are doable on any architecture that supports C. That's easy to show because you can write portable C code that implements them using bit operations on integer types. That is one possible reason why the designers of C decided that the language didn't need to support them directly.
I'm glad they decided that "goto" and "if" were not enough for
flow control :-) F66 designers were not as bright :-D
In article <BE************ *************** ***@laposte.net >,
Jean-Claude Arbaut <je************ ****@laposte.ne t> wrote: I'm glad they decided that "goto" and "if" were not enough for flow control :-) F66 designers were not as bright :-D
Even Fortran I had a DO loop.
[I posted the reference a couple of days ago.]
--
Entropy is the logarithm of probability -- Boltzmann
Le 17/06/2005 21:49, dans d8*********@can opus.cc.umanito ba.ca, «*Walter
Roberson*» <ro******@ibd.n rc-cnrc.gc.ca> a écrit*: In article <BE************ *************** ***@laposte.net >, Jean-Claude Arbaut <je************ ****@laposte.ne t> wrote:
I'm glad they decided that "goto" and "if" were not enough for flow control :-) F66 designers were not as bright :-D
Even Fortran I had a DO loop.
But no WHILE, and if I remember well, it had a strange IF.
I exaggerated, the Fortran language was and still is
a great language. And in 1954, it was an extraordinary
breakthrough. It's just bad luck the language has
evolved to slowly.
> I would like to know why array of bitfields is not possible. Is there any relation with processor architecture for this? Thank you for your time.
Well, on with the shameless plug: if you check my website (the libraries
section) you will find an implementation of a bitmatrix (2 x 2 array of
bits) - it might help you get what you want.
Good luck,
--
Martijn http://www.sereneconcepts.nl
I agree with you.But,if you have programmed in the Keil 8051 C
compiler, you have a datatype called "bit", which can store a value of
0 or 1.It is used to store certain bit-addressable pin values and is
very commonplace in 8051 C.
for Ex,
bit PIN1 = 0;
if(PIN1)
{
.....
}
else
{
....
}
etc.
Eric Sosman wrote: Not in C, you can't.
The problem is that C's array operations are defined in terms of pointers to the array elements -- a[i] is defined to be *(a+i), for example. However, a C pointer cannot point to a bit-field; the "smallest" object a C pointer can point to is a char. Since it's not possible to create a pointer to a bit-field, it's not possible to carry out operations like array indexing that are defined in terms of pointers.
The underlying hardware may be capable of addressing individual bits, but C has no way to use that capability. (The underlying hardware usually has a lot of things C cannot use: circular shifts, a "carry" flag, memory protection, vector instructions, hyperthreading, and so on. C's vocabulary is not rich enough to talk about such things, so C programs cannot use them.)
-- Eric Sosman es*****@acm-dot-org.invalid This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: tmartsum |
last post by:
I have a discussion in comp.std.c++
After a (bit stupid) suggestion on representing a fixed
'big' length int I moderated it to
"Bitfields-ints should be allowed to have any fixed length"
I got no replys on my moderated suggestion.
(I am asking you your opinion of this - I do not really have a
C++-problem)
|
by: Régis Troadec |
last post by:
Hi all,
I follow c.l.c. for only a short time and I would like to know
why there isn't anything concerning bitfields among the FAQs.
Is it because ...
1. of portability issues?
2. bitfields aren't enough useful to be discussed?
3. of the low frequency of questions concerning this topic?
4. of anything else?...
|
by: rohit |
last post by:
Hi,
In my couple of years of experience, I have never found a single
instance where I needed to use unions and bitfields(though I have used
structures).I was just imagining where would these find
relevance.Though both of these(bitfields and unions) are used where
space is a constraint(so I can assume always in embedded systems,where
memory is particularly less)and we want to save space/memory.
As far as I have read, there is no...
|
by: GalenTX |
last post by:
I am looking for opinions on a possible approach to coping with
bitfields in a heterogenous environment.
We've got a bunch of legacy code which maps to hardware using
bitfields. The code was developed for a PowerPC/VxWorks/Tornado
enviromant, with the bits packed in a big-endian manner: msb first. We
now have to develop an Intel/Windows/MSVC++ version (lsb assigned
first) which must maintain compatibility with the hardware interface...
|
by: Benjamin M. Stocks |
last post by:
Hello all,
I've heard differing opinions on this and would like a definitive
answer on this once and for all. If I have an array of 4 1-byte values
where index 0 is the least signficant byte of a 4-byte value. Can I use
the arithmatic shift operators to hide the endian-ness of the
underlying processor when assembling a native 4-byte value like
follows:
unsigned int integerValue;
unsigned char byteArray;
| |
by: Dave |
last post by:
I need to rewrite the following using shifts and masks for portability
sakes, and to get rid of the BYTE_ORDER issue.
/* CODE */
struct test {
#if BYTE_ORDER == BIG_ENDIAN
unsigned char ver:4;
unsigned char res1:4;
#else
unsigned char res1:4;
|
by: richard_l |
last post by:
Hello All,
I am writing an application which receives a word which is a bitmap. I
have created a word typedef which contains a bitfield defining each
bit. however, I was wondering however if it would be better to write a
macro to access each bit instead of the bitfield.
I have read the C-FAQ on bit fields, but was wondering if there were
any advantages/disadvantages to using bit shifting. To my mind I think
using bitfields are more...
|
by: cman |
last post by:
Who can explain to me what bitfields are and how to use them in
practice? I would need a fairly detailed explaination, I would be a
newbie to advanced C programming features. What are the advantages of
using bitfields?
cman
|
by: Ramesh |
last post by:
Hi
I have a structure as below on big endian based system
typedef struct
{
unsigned long LedA:5;
unsigned long LedB:4;
unsigned long LedC:8;
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |