C
codefixer
Hi,
I was wondering what will be the output for this piece of code. I am in
confusion regarding the promotions of bitfield. If your reply is to
compile, execute and check out myself, Thank you please don't read any
further.
Please don't execute the code. I want to know the results according to
the standards.
If an int can represent all values of the original type, the value is
converted to an int; otherwise, it is converted to an unsigned int.
These are called the integer promotions.48) All other types are
unchanged by the integer promotions.
For the following code,
Do you think the program must output "Inside bitfield promoted to
signed int"
#include <stdio.h>
Struct Temp
{
unsigned int a:4;
unsigned int b:32;
};
int main(void)
{
struct Temp s;
s.a = 0;
s.b = 0;
if (s.a - 5 < 0)
printf(" Inside bitfield promoted to signed int\n");
else
printf("Inside bitfield promoted to unsigned int\n");
return 0;
}
Thank you for the time and patience.
I was wondering what will be the output for this piece of code. I am in
confusion regarding the promotions of bitfield. If your reply is to
compile, execute and check out myself, Thank you please don't read any
further.
Please don't execute the code. I want to know the results according to
the standards.
From ISO/IEC 9899:1999 (E) Section 6.3.1.1
If an int can represent all values of the original type, the value is
converted to an int; otherwise, it is converted to an unsigned int.
These are called the integer promotions.48) All other types are
unchanged by the integer promotions.
For the following code,
Do you think the program must output "Inside bitfield promoted to
signed int"
#include <stdio.h>
Struct Temp
{
unsigned int a:4;
unsigned int b:32;
};
int main(void)
{
struct Temp s;
s.a = 0;
s.b = 0;
if (s.a - 5 < 0)
printf(" Inside bitfield promoted to signed int\n");
else
printf("Inside bitfield promoted to unsigned int\n");
return 0;
}
Thank you for the time and patience.