>>107719018
its an array
the address of an array is the same of its first element
the difference in behaviour in picrel, bw s_str_a and s_str_b emerges from the same property- one "shadow dereferencing"
youre passing a pointer to putstr, but in one case its a pointer with a dereferencing, in another its an offset
#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);
// emits address of the array
fprintf(stderr, "&(str_b->text) : %p\n", &(str_b->text));
// emits address of the first element of the array
fprintf(stderr, "str_b->text : %p\n", str_b->text);
free(str_a);
free(str_b);
}