- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
Below is Bitfield code -
--------bitfield.c---------
#include
struct
{
int bit1 : 1;
int bit2 : 1;
} bits;
bits.bit1 = 1;
bits.bit2 = 1;
int main()
{
return 0;
}
--
When using ICC-v11.0 on Linux x86_64, I get below messages -
--
bitfield.c(9): warning #77: this declaration has no storage class or type specifier
bits.bit1 = 1;
^
bitfield.c(9): error: declaration is incompatible with "struct bits" (declared at line 7)
bits.bit1 = 1;
^
bitfield.c(9): error: expected a ";"
bits.bit1 = 1;
^
bitfield.c(10): warning #77: this declaration has no storage class or type specifier
bits.bit2 = 1;
^
bitfield.c(10): error: expected a ";"
bits.bit2 = 1;
^
compilation aborted for bitfield.c (code 2)
--
I did try with unsigned too.
~BR
Below is Bitfield code -
--------bitfield.c---------
#include
struct
{
int bit1 : 1;
int bit2 : 1;
} bits;
bits.bit1 = 1;
bits.bit2 = 1;
int main()
{
return 0;
}
--
When using ICC-v11.0 on Linux x86_64, I get below messages -
--
bitfield.c(9): warning #77: this declaration has no storage class or type specifier
bits.bit1 = 1;
^
bitfield.c(9): error: declaration is incompatible with "struct
bits.bit1 = 1;
^
bitfield.c(9): error: expected a ";"
bits.bit1 = 1;
^
bitfield.c(10): warning #77: this declaration has no storage class or type specifier
bits.bit2 = 1;
^
bitfield.c(10): error: expected a ";"
bits.bit2 = 1;
^
compilation aborted for bitfield.c (code 2)
--
I did try with unsigned too.
~BR
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The problem is that you can't put assignment statements like "bits.bit1 = 1;" at global scope.
You either need to move them inside main() or initialize the structure using an aggregate initializer
list, i.e.:
struct
{
int bit1 : 1;
int bit2 : 1;
} bits = { 1, 1 };
Judy
You either need to move them inside main() or initialize the structure using an aggregate initializer
list, i.e.:
struct
{
int bit1 : 1;
int bit2 : 1;
} bits = { 1, 1 };
Judy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Judith Ward (Intel)
The problem is that you can't put assignment statements like "bits.bit1 = 1;" at global scope.
You either need to move them inside main() or initialize the structure using an aggregate initializer
list, i.e.:
struct
{
int bit1 : 1;
int bit2 : 1;
} bits = { 1, 1 };
Judy
You either need to move them inside main() or initialize the structure using an aggregate initializer
list, i.e.:
struct
{
int bit1 : 1;
int bit2 : 1;
} bits = { 1, 1 };
Judy
You also have the additional problem that a 1 bit int will hold values of 0 and -1.
If you want values of 0 and 1 then use "unsigned bit1: 1"
Jim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Judith Ward (Intel)
The problem is that you can't put assignment statements like "bits.bit1 = 1;" at global scope.
You either need to move them inside main() or initialize the structure using an aggregate initializer
list, i.e.:
struct
{
int bit1 : 1;
int bit2 : 1;
} bits = { 1, 1 };
Judy
You either need to move them inside main() or initialize the structure using an aggregate initializer
list, i.e.:
struct
{
int bit1 : 1;
int bit2 : 1;
} bits = { 1, 1 };
Judy
~BR
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page