2

I'm trying to compile a simple header with some structs but I'm getting this error:

ppal.h:25:34: error: typedef ‘string_proc_func’ is initialized (use decltype instead)
typedef void (*string_proc_func)(string_proc_key*);

There are a bunch of other errors but I think this one is the one causing the others. My header looks like this:

#include <stdint.h>
using namespace std;

typedef struct string_proc_list_t
{
    char* name;
    struct string_proc_node_t* first;
    struct string_proc_node_t* last;
} __attribute__((__packed__)) string_proc_list;


typedef struct string_proc_node_t
{
    struct string_proc_node_t* next;
    struct string_proc_node_t* previous;
    string_proc_func f;
    string_proc_func g;
    string_proc_func_type type;
} __attribute__((__packed__)) string_proc_node;

typedef void (*string_proc_func)(string_proc_key*);

typedef enum string_proc_func_type_t
{
    REVERSIBLE = 0,
    IRREVERSIBLE = 1
} __attribute__((__packed__)) string_proc_func_type;

typedef struct string_proc_key_t
{
    uint32_t length;
    char* value;
} __attribute__((__packed__)) string_proc_key;

I looked for similar questions but I can't find how to fix this.

BobMorane
  • 3,870
  • 3
  • 20
  • 42
  • 3
    Did you try using `decltype`, as the error suggests? – autistic Apr 03 '18 at 02:57
  • It's also worth noting, you shouldn't hide levels of pointer indirection behind `typedef`, because it makes life for maintainers much more difficult. Consider `typedef void string_proc_func(string_proc_key *);` instead... and where you would declare `string_proc_func x`, declare `string_proc_func *x` instead. – autistic Apr 03 '18 at 03:02
  • 1
    Also [`using namespace std` is considered bad enough](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice), but using it in a header file is asking for a lot of trouble – Tas Apr 03 '18 at 03:05
  • Sebivor - m not sure decltype works for pointers to functions the same way as typedef? – Matias Naselli Apr 03 '18 at 03:19
  • If `__attribute__((__packed__)) ` does what the name suggests, won't `char* value` be misaligned? What is the purpose? – Jive Dadson Apr 03 '18 at 03:30
  • The code has too many errors not associated with the one in the question. Post a [MCVE] – Jive Dadson Apr 03 '18 at 03:35

1 Answers1

2

You are trying to use string_proc_key before its declaration.

Move the line with the error underneath the typedef struct ... string_proc_key;

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720