This question already has answers here:
typedef fixed length array
(7 answers)
Closed 4 years ago.
I found this line of code and I didn't understand how can you typedef a uint8 to something that isn't a type in the first place like x[4]?
What is really meant here ? Is it an just an array of 4 uint8 type variables and that is just another way of saying it?
Code:
Typedef uint8 x[4]
The syntax of a typedef matches the syntax of a declaration. In this case, x is a type alias for uint8[4].
Related
This question already has answers here:
What does a colon in a struct declaration mean, such as :1, :7, :16, or :32?
(3 answers)
Closed 1 year ago.
I'm reading about structs in C and I came across some interesting declaration that I don't know what does is mean. The declaration goes as follows:
typedef struct name{
int x :1;
}name;
what does line 'int x :1;' mean ? is 1 the default value of x?
Would appreciate help! Thanks
It specifies the number of bits to use for that field. It is called "bit field".
Check this: https://en.cppreference.com/w/cpp/language/bit_field
This question already has answers here:
How to create a typedef for function pointers
(3 answers)
Closed 5 years ago.
I was going through one of the lecture slide taught in the class which included a typedef keyword in it. As opposed to normal use of typedef keyword where we usually put a alias for particular data, there was no alias put up for that example. Following is the example:See the typedef in the slide
Is the use of typedef correct, or am I interpreting differently?
It is a function pointer. And it is perfectly valid syntax.
Ptr is declared as a pointer to a function where the function takes two int arguments and return an int. Here you can use Ptr as the alias to the typedefed type.
This question already has answers here:
What does a colon in a struct declaration mean, such as :1, :7, :16, or :32?
(3 answers)
Closed 6 years ago.
I'm working with a piece of code and I come across with something similar to this:
struct {
int a : 1;
int b : 1;
};
I don't know what is the function of : 1 here. For your interest, that struct is inside a union which in turn is inside a typedef struct.
Thanks,
This is used to assign value to a bit. You can read about bitfields here.
This question already has answers here:
What does a colon in a struct declaration mean, such as :1, :7, :16, or :32?
(3 answers)
What does the : do in a struct declaration after a member
(1 answer)
What does 'unsigned temp:3' in a struct or union mean? [duplicate]
(4 answers)
Closed 9 years ago.
typedef struct{
unsigned flanke:1;
unsigned lastState:1;
} flanke_t;
I do not understand the ":1". Please help me, thx.
These are bit fields: https://en.wikipedia.org/wiki/Bit_field. Here you just reserve 1 bit for 'flanke' and one for the 'lastState'. The type has to be unsigned int.
What you see here is bit field declaration usage. it is used to indicate the number of bits a given structure member will occupy in the structure so its main usage is to pack a structure so that it occupies less memory.
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
What does 'unsigned temp:3' means
I don't understand this struct definition. It seems illegal to me, but apparently it isn't:
typedef struct
{
unsigned i:1;
} my_struct;
I believe that marking the variable as unsigned without a type is the same as marking it as unsigned int. However, I'm completely baffled by the colon. What does it do? My guess is that it's some sort of initializer, but I haven't a clue what it means. Off the top of my head, the only place that I'd expect a colon in C is in the ternary operator, which this obviously isn't. So, this appears to be a construct with which I am not familiar. Can anyone explain what the purpose of the colon is in this struct definition? What exactly does the declaration unsigned i:1; mean?
It defines i to be of 1 bit width.
If i:x is given then it defines i to be x bits wide.