Linked Questions

0 votes
0 answers
646 views

Whats does the : symbol means in c structure. The code below supposed to show output 12 (size of int=4,size of structure=sum of each structure member) But it is showing 8 as output. #include<...
Dora's user avatar
  • 3
-4 votes
1 answer
166 views

This was a code snippet from a test question. The question was what the size of S would be. struct S { char a : 4; unsigned char b : 3; signed char : 2; char c : 1; char d : 5; }...
black-goat's user avatar
1 vote
1 answer
136 views

In a project of STM32, I came through a code like this : typedef union { struct __attribute__ ((packed)){ uint8_t ModePin0 :1; uint8_t ModePin1 :1; ...
BeamString's user avatar
24 votes
4 answers
7k views

I long knew there are bit-fields in C and occasionally I use them for defining densely packed structs: typedef struct Message_s { unsigned int flag : 1; unsigned int channel : 4; ...
wirrbel's user avatar
  • 3,299
11 votes
6 answers
3k views

This is about ANSI-C (C90). This is what I know: I can directly tell the compiler how many bits I want for a specific variable. If I want 1 bit which can have the values zero or one. or 2 bits for ...
idan di's user avatar
  • 241
4 votes
3 answers
5k views

Hi I want to declare a 12 bit variable in C or any "unconventional" size variable (a variable that is not in the order of 2^n). how would I do that. I looked everywhere and I couldn't find anything. ...
Igal Flegmann's user avatar
0 votes
2 answers
8k views

I know there is another post here that is how to clear a single bit, but how about a whole byte? For example, if I had 00000000 00000000 00101100 11000100 and I wanted to clear the second chunk so it ...
PhantomProgramer's user avatar
6 votes
1 answer
2k views

From K&R The C Programming Language: A non-field member of a structure or union may have any object type. A field member (which need not have a declarator and thus may be unnamed) ...
Tim's user avatar
  • 101k
0 votes
1 answer
3k views

I'm trying to learn more about PE files structures and also ctypes structures. I got a couple of questions: Given this simple declaration: from ctypes import * class ImageDosHeader(Structure): ...
BPL's user avatar
  • 9,985
0 votes
1 answer
1k views

Is this legal? I read that you can only use integers as bitfields, but does this apply to the bool/_Bool types? Is this OK, or is this undefined behavior somehow? struct MyStruct { // ... bool ...
CPlus's user avatar
  • 5,110
0 votes
2 answers
953 views

Code from this link: https://github.com/openwch/arduino_core_ch32/blob/main/libraries/USBPD_SINK/src/usbpd_def.h I am looking at the previous file. I did some search and found something about unsign ...
Bao Ng's user avatar
  • 3
2 votes
4 answers
2k views

I saw multiple adjacent bit fields while browsing cppreference. unsigned char b1 : 3, : 2, b2 : 6, b3 : 2; So, What is the purpose of it? When and where should I use it?
msc's user avatar
  • 35.1k
3 votes
2 answers
431 views

There's a lot of advice out there saying not to use bitfields but to do the bit arithmetic manually (e.g., When to use bit-fields in C?) because bitfield layouts are implementation-defined. Is this ...
Petr Skocik's user avatar
  • 60.6k
0 votes
2 answers
449 views

Recently I stumbled upon a code written like this: typedef struct { uint8_t TC0_WG0 :2; uint8_t TC0_CS :3; } Timer0; What I wanted to know is what does the part that says :2; & :3; ...
Mahmoud Ayman's user avatar
1 vote
2 answers
154 views

I am beginner in C and can't understood how this piece of code is working: struct marks{ int p:3; int c:3; int m:2; }; void main(){ struct marks s={2,-6,5}; printf("%d %d %d", s.p, s.c, s....
user avatar

15 30 50 per page