473,379 Members | 1,170 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Doubt in structure bitfields

Expand|Select|Wrap|Line Numbers
  1. struct date{
  2.          unsigned short int day:5;
  3.          unsigned short int mon:4;
  4.          unsigned short int year:12;
  5. }dt;
  6. dt.day=12;
  7. dt.mon=5;
  8. dt.year=2000;
  9. 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 'BITS' only how it is retrieving correctly.
Please clarify my doubt.
Nov 9 '06 #1
2 1620
Banfa
9,065 Expert Mod 8TB
Any integer type <= to the size of an int is passed to a function that does not specify the parameter type (which printf doesn't because it has a variable parameter list) as an int

This is why %d works for char, short and int as well as bit fields, they are all passed on the stack as int.
Nov 9 '06 #2
Thank you verymuch.
Nov 12 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
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...
13
by: - Kees van der Bent - | last post by:
/* With the following: */ typedef struct { unsigned char a : 1; unsigned char b : 1; } sss_t; sss_t sss; unsigned char ppp; main()
15
by: damian birchler | last post by:
Hi I'm wondering of what type a structure is. Of course, it is a _structure_, but an array isn't an _array_ either. So of what type is a structure? I'd say a pointer, am I right?
6
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...
10
by: ranjeet.gupta | last post by:
Dear All !! Before i qoute my querry, I will like to qoute my analysis and my Knowledge Struct a { int raw; char data; };
14
by: Kavya | last post by:
Here is the code int main(){ struct node{ int a; int b; int c; }; struct node s={3,5,6}; struct node *ptr=&s;
1
by: fdmfdmfdm | last post by:
code like: struct pid_tag{ unsigned int inactive : 1; unsigned int : 1; /* 1 bit of padding */ unsigned int refcount : 6; unsigned int : 0; /* pad to next word boundary...
3
by: nass | last post by:
hello everyone, i read somewhere that it is possible to define a BitFields structure so i set out to: struct IC_X { unsigned short int dump:2; unsigned short int ic1:10; unsigned short int...
3
by: David d'Angers | last post by:
hi group i read this in the linux version "tree" program struct _info { char *name; char *lnk; u_char isdir : 1; u_char issok : 1; u_char isexe : 1;
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.