473,698 Members | 2,616 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

bitfields as static members?

Hello,

I'm attempting to define a class that has a bitfield as a static
member. The definition seems ok, but I'm at a loss as to how to declare
it:

class Test {
static struct TestBitFields {
unsigned int Flag1:1;
unsigned int Flag2:1;
} BitFields;
};

Thanks in advance!

Apr 14 '06 #1
3 1787

TedKennedyMurde redHisPregnantM istress.dwp...@ spamgourmet.com wrote:
Hello,

I'm attempting to define a class that has a bitfield as a static
member. The definition seems ok, but I'm at a loss as to how to declare
it:

class Test {
static struct TestBitFields {
unsigned int Flag1:1;
unsigned int Flag2:1;
} BitFields;
};

Thanks in advance!


Er, please ignore the ommission of "public". :-)

Apr 14 '06 #2
Te************* *************** **...pamgourmet.com wrote:
I'm attempting to define a class that has a bitfield as a static
member. The definition seems ok, but I'm at a loss as to how to
declare it:

class Test {
static struct TestBitFields {
unsigned int Flag1:1;
unsigned int Flag2:1;
} BitFields;
};


I think you got those things in reverse. You already declared the
struct and the member. Now you need to define it:

class Test {
...
};

Test::TestBitFi elds Test::BitFields ;

V
--
Please remove capital As from my address when replying by mail
Apr 14 '06 #3

Victor Bazarov wrote:
Te************* *************** **...pamgourmet.com wrote:
I'm attempting to define a class that has a bitfield as a static
member. The definition seems ok, but I'm at a loss as to how to
declare it:

class Test {
static struct TestBitFields {
unsigned int Flag1:1;
unsigned int Flag2:1;
} BitFields;
};
I think you got those things in reverse. You already declared the
struct and the member. Now you need to define it:


Duh, you're right. Thanks for pointing out my oversight!
class Test {
...
};

Test::TestBitFi elds Test::BitFields ;


Works like a charm; thanks. Even got initialization going. :-)

Apr 14 '06 #4

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

Similar topics

2
3180
by: Grumfish | last post by:
In order to familiarize my self with Flash files and their bytecode I've started to make an assembler. My first problem is writing the bitfields the format uses often. It is a series of fields, each can be a different number of bits, combined into the least amount of bytes possible. Extra bits in the last byte are padded with zeros. I would like to make a function that takes a size and value for each field needed, calculate the amount of...
3
3600
by: DanielBradley | last post by:
Hello all, I have recently been porting code from Linux to cygwin and came across a problem with static const class members (discussed below). I am seeking to determine whether I am programming non-standard C++ or if the problem lies elsewhere. To summarize static const class members are not being accessed properly when accessed from a DLL by another external object file (not within the DLL). It only occurs when the static const...
8
1905
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
2822
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...
2
8133
by: Jason Curl | last post by:
Hello C Group, From what I remember, it is implementation dependent the way that a compiler may order bitfields in a struct. In the example program I give, Solaris Sparc gives one result, Intel x86 gives another result (for the GCC compiler). Is there a portable way to test how this information is stored? In particular, will the result of the program below always result in c being 0x01 or 0x80? Does the compiler allow for padding so...
11
3831
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you experts. I would like to produce Javascript classes that can be "subclassed" with certain behaviors defined at subclass time. There are plenty of ways to do this through prototyping and other techniques, but these behaviors need to be static and...
7
3823
by: gert.vierman | last post by:
Hello, Here is some code mixing bitfields and longs in an union. Any comments on the validity and portability of this program ? Thank you very much. #include <stdio.h> union msg_t {
2
1635
by: sureshk | last post by:
struct date{ unsigned short int day:5; unsigned short int mon:4; unsigned short int year:12; }dt; dt.day=12; dt.mon=5; dt.year=2000; printf("%d:%d:%d",dt.day,dt.mon,dt.year); In the above code the members of the structure are bitfields. we are trying to print those values using %d. "%d" is actually used to retrieve an integer of 2 or 4bytes accorind to the wordsize of the CPU, but here it is of 5,4 or 12...
9
19254
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
0
8610
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
9031
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...
1
8902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8873
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
7740
agi2029
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...
1
6528
isladogs
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...
0
5862
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
4372
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...
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.