473,756 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Array of bitfields

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
Nov 14 '05
19 14811
"Mehta Shailendrakumar " <sh************ *******@de.bosc h.com> writes:
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.


Bitfields aren't addressable; you can't take the address of a
bitfield with the '&' operator, for example.

Because bitfields aren't addressable, they can't be used for
arrays, because of how arrays and pointers work. No addresses,
no arrays.

An array of bitfield values may be manufactured using a struct,
thusly:

struct { unsigned value:4; } bitfield_array[10];

i = bitfield_array[0].value;
bitfield_array[1].value = j;

Of course, the values in the array won't be tightly packed.
There will be unused space between the values, unless the number
of bits and the padding requirements for the struct that the
values are in happen by lucky coincidence to leave no wasted
space. But if what you want is an array of bitfield values
and some inter-field padding doesn't matter, this approach
could fill the bill.
Nov 14 '05 #11
ya*******@gmail .com wrote:

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;


That looks like C to you?
If that's 8051 C, then 8051 C, isn't C.

--
pete
Nov 14 '05 #12
pete <pf*****@mindsp ring.com> wrote:
# ya*******@gmail .com wrote:
# >
# > 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;
#
# That looks like C to you?
# If that's 8051 C, then 8051 C, isn't C.

ANSI doesn't have a trademark on the third letter of the alphabet.
There are many varieties of C other than ANSI's.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
God's a skeeball fanatic.
Nov 14 '05 #13

Le 18/06/2005 15:53, dans 11************* @corp.supernews .com, «*SM Ryan*»
<wy*****@tang o-sierra-oscar-foxtrot-tango.fake.org> a écrit*:
pete <pf*****@mindsp ring.com> wrote:
# ya*******@gmail .com wrote:
# >
# > 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;
#
# That looks like C to you?
# If that's 8051 C, then 8051 C, isn't C.

ANSI doesn't have a trademark on the third letter of the alphabet.
There are many varieties of C other than ANSI's.


Standards are written to avoid spreading of incompatible compilers
(and probably many other good reasons).
You can invent a BASIC-like language and call that C if this pleases you,
but don't come on c.l.c, cause this IS related to ISO C.
If you really don't understand what a standard benefit is, just have a look
at Fortran history before standardization . Look also at BASIC, not
standardized as far as I know, and a least I don't know any two compilers
for the same BASIC variant.

Nov 14 '05 #14
# but don't come on c.l.c, cause this IS related to ISO C.

If you wanted a moderated newsgroup, then make a moderated newsgroup.
Until then, you don't get to decide what other people post.

# If you really don't understand what a standard benefit is, just have a look

Irrelevant. Neither ANSI nor ISO owns a trademark on 'C'.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
So....that would make Bethany part black?
Nov 14 '05 #15

Le 18/06/2005 17:03, dans 11************* @corp.supernews .com, «*SM Ryan*»
<wy*****@tang o-sierra-oscar-foxtrot-tango.fake.org> a écrit*:
# but don't come on c.l.c, cause this IS related to ISO C.

If you wanted a moderated newsgroup, then make a moderated newsgroup.
Until then, you don't get to decide what other people post.


That's right, but it doesn't prevent from flaming. I was several times for
the same reason. Now I know what c.l.c is for, I am careful.

If you wanted a non-ISO C newsgroup, then make a comp.lang.c.bla bla.
Until then, you don't get to decide what is valid here. BTW I considered
this option, but c.l.c and comp.programmin g are sufficient for my usage.

Nov 14 '05 #16
SM Ryan wrote:
# but don't come on c.l.c, cause this IS related to ISO C.

If you wanted a moderated newsgroup, then make a moderated newsgroup.
Until then, you don't get to decide what other people post.

# If you really don't understand what a standard benefit is, just have a look

Irrelevant. Neither ANSI nor ISO owns a trademark on 'C'.


Your post before this merely showed ignorance; this one exposes you as a
troll.
*PLONK*
Nov 14 '05 #17
Martin Ambuhl wrote:
SM Ryan wrote:
# but don't come on c.l.c, cause this IS related to ISO C.

If you wanted a moderated newsgroup, then make a moderated newsgroup.
Until then, you don't get to decide what other people post.

# If you really don't understand what a standard benefit is, just

Irrelevant. Neither ANSI nor ISO owns a trademark on 'C'.


Your post before this merely showed ignorance; this one exposes
you as a troll.
*PLONK*


He has been long gone from here, primarily for inability to mark
quotes correctly. Another indication of a non-intelligent troll.

--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Nov 14 '05 #18
In article <42************ ***@yahoo.com>,
CBFalconer <cb********@wor ldnet.att.net> wrote:
He has been long gone from here, primarily for inability to mark
quotes correctly.


There is no "correct" way to mark quotes: only -conventions-
that are followed to various degrees. If you feel that there
is a "correct" way to mark Usenet quotes, then you are welcome to
cite an RFC, IEEE standard, ISO standard, page in K&R (any
edition), any book by K., R., or P., government regulation
in any country, or statute in -any- jurisdiction which has
the authority to create criminal offenses.

And No, the behaviour of your newsreader or of Google Groups
in automatic colorization or other forms of highlighting
are -not- evidence of "correct" behaviour.
Keith got it right months ago: there is no "correct" way of
marking quotes, just ways that irritate different sets of people.

-Every- quoting convention offends -someone-; it is up to each
individual to choose which set of people they are willing to offend.

--
"I want to make sure [a user] can't get through ... an online
experience without hitting a Microsoft ad"
-- Steve Ballmer [Microsoft Chief Executive]
Nov 14 '05 #19
>> He has been long gone from here, primarily for inability to mark
quotes correctly.
There is no "correct" way to mark quotes: only -conventions-
that are followed to various degrees.


[snipped]
-Every- quoting convention offends -someone-; it is up to each
individual to choose which set of people they are willing to offend.


Just like "incorrect" separators for the signatures. Then again, these
conventions are there to make the life of a poster more convenient, and I
comply only for that reason. And honestly, a _lot_ of software depends on
those conventions, not only for color highlighting, but also for readjusting
message width and the sorts.

"Can't we all just get along??" :P

--
Martijn
http://www.sereneconcepts.nl
Nov 14 '05 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
400
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)
8
1908
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?...
23
2830
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...
6
2683
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...
33
3415
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;
3
2425
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;
18
4731
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...
9
19259
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
2
4055
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;
0
9456
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9275
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,...
0
10034
Oralloy
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...
0
9872
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9713
tracyyun
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...
0
6534
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();...
0
5142
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...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.