Flexible Array Members | C Programming Tutorial

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

Very good tutorial! I love your stil! Thank you so much!

One thing I have missed:
The flexible array member does not need any space itself. So far so good.
However, more space can be incurred by the alignment.

struct data
{
char c;
int array[];
};

Sizeof struct data now results in 4 bytes and not 1 byte, which one might have expected. This, although the flexible array member does not need any space.
But since the elements of the flexible array member must always come directly to the end of the structure and these in turn must be aligned according to their types, the compiler inserts padding within the structure depending on the situation (alignment of int is "normally" a multiple of 4).

The following structure has now a sizeof of 16 bytes (alignment of long long is "normally" a multiple of 8):
struct data
{
char elements[9];
long long array[];
};

Maybe a topic for another video (This and the topic of alignment in general)?
Cheers

starcw
Автор

professor, thank you very much for all these precious tutorials, in addition to the fact that you are a great lecturer, this and many more corner cases which are not covered very much on the internet what separates you from the whole internet. I appreciate each and every video you've published, they're all just great. Thank you for everything, greetings from Turkey 🇹🇷

gpythona
Автор

unrelated but currently learning RV32I and i couldn’t help to imagine how goated portfolio courses would be at teaching the logic of it 🔥

Algebraiic
Автор

fantastic vid, subbed and liked, was super helpful for understanding :)

JamBadguy
Автор

Great 2 hear from u again. Are u feeling better now?

togosakutaro
Автор

Will that flexible member follow structure padding ?

yogeshchauhan
Автор

10:36 Obviously you are creating the struct on the stack here.
Is there any case where it makes sense to create a struct with a flexible array member on the stack?
If this struct is on the stack, any access to the flexible array is UB, because it is not clear what follows behind this struct on the stack.

Or am I perhaps missing something?

Shouldn't it be consequently impossible to create a struct with a flexible array member on the stack?

starcw
Автор

broo thank you so much much love for you
i have a question please can you tell me what's the name of your ide please?

scalping.dom
welcome to shbcf.ru