Home Posts Topics Members FAQ
gunner666
3 New Member
Hi ,i want to know wat the : stands for, or does to the program here below
typedef struct ref
{
unsigned int en:1;
unsigned int sm:4;
unsigned int g:8;
unsigned int gate:16;
}
i want to know what does
en:1 really mean,
is it like assignin the variable en wid 1 ,or is it somethin else
plzzzzz reply
Feb 7 '08 #1
Subscribe Reply
4 1349
gpraghuram 1,275 Recognized Expert Top Contributor
Hi ,i want to know wat the : stands for, or does to the program here belowtypedef struct ref
{
unsigned int en:1;
unsigned int sm:4;
unsigned int g:8;
unsigned int gate:16;
}
i want to know what does
en:1 really mean,
is it like assignin the variable en wid 1 ,or is it somethin else
plzzzzz reply
It is specifying how many bits you are going to use for storing the value.go through this link to get a good idea abt this
Raghuram
Feb 7 '08 #2
reply
krishnabhargav 24 New Member
Hi ,i want to know wat the : stands for, or does to the program here belowtypedef struct ref
{
unsigned int en:1;
unsigned int sm:4;
unsigned int g:8;
unsigned int gate:16;
}
i want to know what does
en:1 really mean,
is it like assignin the variable en wid 1 ,or is it somethin else
plzzzzz reply
Those are called Bit Fields...
en is 1 bit, sm is 4 bits and g is 8 bits while gate is 16 bits
refer : http://www.informit.co m/guides/content.aspx?g= cplusplus&seqNu m=131
Feb 7 '08 #3
reply
krishnabhargav 24 New Member
Simple example to illustrate bitfields
Expand|Select|Wrap|Line Numbers
- #include<iostream>
- usingnamespacestd;
- typedefstructref
- {
- unsignedinti:4;
- unsignedintj:2;
- };
- intmain()
- {
- refr1;
- cout<<sizeof(r1)<<endl;
- r1.j=3;//sincer1is2bits,maxvalueis"11"(binary)or3
- cout<<"Valueofr1.j(2bits)"<<r1.j<<endl;
- r1.j=8;//100inbinary,cannotset100,insteadsets00toj'sbits
- cout<<"Valueofr1.j(2bits)"<<r1.j<<endl;
- }
Feb 7 '08 #4
reply
weaknessforcats 9,208 Recognized Expert Moderator Expert
You are using C++ where bit fields are supported as a deprecated feature only to compile relic C code. You are not supposed to use bit fields in new C++ code.
Use a bitset<>:
Expand|Select|Wrap|Line Numbers
- bitset<32>bits;//32bits
Feb 7 '08 #5
reply
Sign in to post your reply or Sign up for a free account.
Similar topics
4 9013 binary search tree removal - stuck - HELP!! by: Tarique Jawed |last post by: Alright I needed some help regarding a removal of a binary search tree. Yes its for a class, and yes I have tried working on it on my own, so no patronizing please. I have most of the code working, even the removal, I just don't know how to keep track of the parent, so that I can set its child to the child of the node to be removed. IE - if I had C / \ B D C / C++ |
2 2034 Plz Help ..Strucs-->U_char arrays<--Structs by: ANaiveProgrammer |last post by: Hi all I have been trying to send a struct over socket. I tried to assign the values of struct to unsigned char array. I have attached both .c files at the bottom. 'Client.c' takes a struct, arrange the struct in u_char array and send the u_char array to 'Server.c'. Now 'Server.c' takes the u_char array and assign to the struct and displays its values. Now im totally stumped and im facing following problems though i have C / C++ |
8 1367 Regarding use of modules by: Paminu |last post by: I am trying to split my program in different parts. I have a file called mainfile.c that contains the main() function, some global variables and a few other functions. I then have a file called mainfile.h that contains some structs and a list of the functions that are used in mainfile.c I am then trying to make another file called my_func.c that contains some other functions that when called will update some of the global variables C / C++ |
3 1902 C++ Compiler behavior regerding struct constructors by: Karl M |last post by: Hi everyone, I just notice some strange behaviors on the MS C++ compiler regarding struct default constructor, see the example bellow: struct MyStruct { int a; }; class MyClass { public: .NET Framework |
4 2809 Pls help me in VB.net regarding API by: simran |last post by: Hi !!1 I am making on application to contl the volume similar to sndvol32.exe . I got the some code in VB6. I am working in VB.NET so i ma trying to convert that ocde in VB.NET In VB6 i have these two functions in which they have used " As Any" I know that in VB.NET this is not supported but i am not able to find wht will i use insted of that in the declarations part. Visual Basic .NET |
3 1880 Help regarding Josepheus problem. by: Rohini Ramamurthy |last post by: Hi All, I have taken up this problem to learn a bit in using linked lists. I am trying a variant of it what it is supposed to so is delete the nth person clockwise and counter clockwise alternatively until last man is alive I tried coding it. I have completed it. But i have a problem in my code. C / C++ |
1977 Need help regarding accessing structure elements using pointer to array of structures by: harsha1305 |last post by: Hi all, I need to create a pointer to array of structure. Definition of structure: typedef struct { char b_name; unsigned long int sig; unsigned long int count; volatile unsigned char *Su_buffer; C / C++ |
6 2671 Help me/.... by: toch3 |last post by: i am writing a c program that is basically an address book. the only header we are using is #include<stdio.hwe are to use a global array, loops, and pointers. we are to have a menu at the beginning. 1. add new record 2. search for a record 3 modify a record 4. delete a record 5. view all records 6.exit in each of these menu's we are to be able to print the record to an exterior printer. : i have started my global array, and program, but... C / C++ |
5 1292 Help me understand by: QbProg |last post by: Hello, I did some experiments with VC++ 2005, and some ILDasm. Please tell me if I have understood the concepts of C++ programming under .NET, since I'm a bit confused! -- There are 4 types of classes in VC++/CLI: Unmanaged classes (i.e. normal classes compiled in a unmanaged source or dll , the code is unmanaged and CPU native). Accessible from C++/CLI .NET Framework |
2 3788 Question regarding memory alignment by: somenath |last post by: Hi All, I have one question regarding the alignment of pointer returned by malloc. In K&R2 page number 186 one union is used to enforce the alignment as mentioned bellow. typedef long Align; union header { struct { C / C++ |
8132 Changing the language in Windows 10 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,... Windows Server |
8630
Problem With Comparison Operator <=> in G++ 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... C / C++ |
1 8285 The easy way to turn off automatic updates for Windows 10/11 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,... Windows Server |
8436
Discussion: How does Zigbee compare with other wireless protocols in smart home applications? 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... General |
1 6092
Access Europe - Using VBA to create a class based on a table - Wed 1 May 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... Microsoft Access / VBA |
5542 Couldnt get equations in html when convert word .docx file to html file in C#. 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();... C# / C Sharp |
1 2570 transfer the data from one system to another through ip address 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 C# / C Sharp |
1 1751
How to add payments to a PHP MySQL app. by: muto222 |last post by: How can i add a mobile payment intergratation into php mysql website. PHP |
1429
Comprehensive Guide to Website Development in Toronto: Expert Insights from BSMN Consultancy by: bsmnconsultancy |last post by: In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive... General |
By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.
To disable or enable advertisem*nts and analytics tracking please visit the page.