Search Results
6/15/2025, 1:51:04 PM
>>105600117
(ntt)
abstract objects
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct s_str_a
{
size_t size;
char *text;
};
struct s_str_b
{
size_t size;
char text[];
};
int main(void)
{
char text[] = "this is a string";
struct s_str_a *str_a = malloc(sizeof(struct s_str_a));
struct s_str_b *str_b = malloc(sizeof(struct s_str_b) + sizeof(text));
str_a->text = text;
strcpy(str_b->text, text);
puts(str_a->text);
puts(str_b->text);
}
the practical difference is an additional level of dereferencing
(ntt)
abstract objects
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct s_str_a
{
size_t size;
char *text;
};
struct s_str_b
{
size_t size;
char text[];
};
int main(void)
{
char text[] = "this is a string";
struct s_str_a *str_a = malloc(sizeof(struct s_str_a));
struct s_str_b *str_b = malloc(sizeof(struct s_str_b) + sizeof(text));
str_a->text = text;
strcpy(str_b->text, text);
puts(str_a->text);
puts(str_b->text);
}
the practical difference is an additional level of dereferencing
Page 1