I'm trying to anonymously create a struct using a couple variables and gcc, given the flag -Werror, won't compile the following:
char file_name[A1FS_NAME_MAX];
strcpy(file_name, strrchr(path, '/') + 1);
a1fs_dentry *new_dentry_ptr = (a1fs_dentry *) fs->data_table + last_extent->start * A1FS_BLOCK_SIZE + remaining_directory_entries * sizeof(a1fs_dentry);
*new_dentry_ptr = (a1fs_dentry) {
.ino = (a1fs_ino_t) fs->first_free_inode_i,
.name = file_name
};
where a1fs_dentry is defined as follows:
typedef struct a1fs_dentry {
/** Inode number. */
a1fs_ino_t ino;
/** File name. A null-terminated string. */
char name[A1FS_NAME_MAX];
} a1fs_dentry;
The warning causing it to fail is at .name = file_name. It also says error: missing braces around initializer. I tried casting file_name to a char array but it doesn't like that. My goal is to get it to where it doesn't give those warnings anymore.