Click here to Skip to main content
15,886,919 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: MultiThread Question Pin
ForNow8-Jan-18 3:03
ForNow8-Jan-18 3:03 
Questionarray and pointer Pin
Anonygeeker7-Jan-18 18:02
Anonygeeker7-Jan-18 18:02 
AnswerRe: array and pointer Pin
Rick York7-Jan-18 18:56
mveRick York7-Jan-18 18:56 
AnswerRe: array and pointer Pin
CPallini7-Jan-18 21:44
mveCPallini7-Jan-18 21:44 
AnswerRe: array and pointer Pin
cao_aba39-Jan-18 15:55
cao_aba39-Jan-18 15:55 
GeneralRe: array and pointer Pin
Richard MacCutchan9-Jan-18 22:26
mveRichard MacCutchan9-Jan-18 22:26 
QuestionWhat am I doing wrong defining single bit? Pin
Vaclav_7-Jan-18 12:36
Vaclav_7-Jan-18 12:36 
AnswerRe: What am I doing wrong defining single bit? Pin
leon de boer7-Jan-18 15:23
leon de boer7-Jan-18 15:23 
You can only have bit fields in a struct or union, it would be physically stupid to have them outside a struct or union because they couldn't be packed anyhow you might as well pick any normal type. Your somewhat pointless definition (it saves zero memory space) would be
typedef struct {
    unsigned bit : 1; // single bit
} BIT;

The initialize would be
static BIT bit = { 0 };
or  
static BIT bit = {.bit = 0}; // C11 and above standard

The only point to bit fields is to save space or make naming and offsets easier in particular for hardware registers.
The other recommendation I make is only define them as sign or unsigned you don't have to assign a normal C type the
compiler internally knows how to cast bit fields to do operations on them.

Usually what you are doing on hardware registers is assigning the bits to match something like an 8 bit definition
typedef struct __attribute__((__packed__, aligned(1))) {
    unsigned Clk : 1; // clk bit
    unsigned Bit : 1; // Data bit
    unsigned CS : 1;  // Chip select
    unsigned _reserved: 5; // 5 unused bits
} MYREGISTER;

In the above you have 8 bits packed into a byte so it saves space carrying them.
In vino veritas


modified 7-Jan-18 21:41pm.

GeneralRe: What am I doing wrong defining single bit? Pin
Vaclav_8-Jan-18 5:37
Vaclav_8-Jan-18 5:37 
QuestionC program to reverse the order of the words entered. Pin
Tarun Jha7-Jan-18 6:45
Tarun Jha7-Jan-18 6:45 
GeneralRe: C program to reverse the order of the words entered. Pin
PIEBALDconsult7-Jan-18 7:01
mvePIEBALDconsult7-Jan-18 7:01 
SuggestionRe: C program to reverse the order of the words entered. Pin
David Crow7-Jan-18 15:50
David Crow7-Jan-18 15:50 
QuestionWrite data to file which cannot be viewed Pin
manoharbalu5-Jan-18 2:09
manoharbalu5-Jan-18 2:09 
SuggestionRe: Write data to file which cannot be viewed Pin
David Crow5-Jan-18 2:16
David Crow5-Jan-18 2:16 
AnswerRe: Write data to file which cannot be viewed Pin
Richard MacCutchan5-Jan-18 2:35
mveRichard MacCutchan5-Jan-18 2:35 
AnswerRe: Write data to file which cannot be viewed Pin
jschell5-Jan-18 13:45
jschell5-Jan-18 13:45 
AnswerRe: Write data to file which cannot be viewed Pin
leon de boer6-Jan-18 4:45
leon de boer6-Jan-18 4:45 
QuestionWriting a huge structure data to file Pin
manoharbalu4-Jan-18 22:29
manoharbalu4-Jan-18 22:29 
AnswerRe: Writing a huge structure data to file Pin
Richard MacCutchan4-Jan-18 23:27
mveRichard MacCutchan4-Jan-18 23:27 
AnswerRe: Writing a huge structure data to file Pin
jschell5-Jan-18 13:49
jschell5-Jan-18 13:49 
AnswerRe: Writing a huge structure data to file Pin
leon de boer6-Jan-18 4:11
leon de boer6-Jan-18 4:11 
QuestionHow to return a string from a user defined function to main function ? Pin
Tarun Jha3-Jan-18 3:21
Tarun Jha3-Jan-18 3:21 
AnswerRe: How to return a string from a user defined function to main function ? Pin
David Crow3-Jan-18 6:24
David Crow3-Jan-18 6:24 
GeneralRe: How to return a string from a user defined function to main function ? Pin
Tarun Jha3-Jan-18 7:20
Tarun Jha3-Jan-18 7:20 
GeneralRe: How to return a string from a user defined function to main function ? Pin
David Crow3-Jan-18 7:29
David Crow3-Jan-18 7:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.