0

I replicated the guidance provided here but continue receiving the following error for each line with a function header and prototype: 'typedef "Neuron" may not be used in an elaborated type specifier'. I researched this error and didn't find much useful content. Any help would be most appreciated.

#include <stdio.h>
#include <stdlib.h>

struct neuronHead {
  int x, y, z;                    
  neuronHead *apical[25];  
  neuronHead *basal[25];    
  neuronHead *axon[25];      
  int time;                       
} neuron;

typedef struct neuron Neuron;

void setupBrain(struct Neuron ****brain); /* brain is a 3D array of structs */
void freeBrain(struct Neuron ****brain);

int main(void) {
   Neuron ***brain;

   setupBrain(&brain);
   freeBrain(&brain); }

void setupBrain(struct Neuron ****brain) {
   /* code for malloc'ing a 3D array of structures */ }

void freeBrain(struct Neuron ****brain) {
   /* code for freeing the 3D array of structures */ }

I'm running on Ubuntu 14.04 and using Nvidia's NVCC compiler to run the code on GPUs, though this shouldn't be relevant to the error at hand.

Community
  • 1
  • 1
Pete Janda
  • 73
  • 8

3 Answers3

0

In your code, there is no struct neuron you can typedef to. In your case, neuron is a global variable of type struct neuronHead.

You need to change your code to

struct neuronHead {
  int x, y, z;                    
  struct neuronHead *apical[25];  
  struct neuronHead *basal[25];    
  struct neuronHead *axon[25];      
  int time;                       
};

typedef struct neuronHead Neuron;

or,

typedef struct neuronHead Neuron;

struct neuronHead {
  int x, y, z;                    
  Neuron *apical[25];  
  Neuron *basal[25];    
  Neuron *axon[25];      
  int time;                       
};

or,

  typedef struct neuronHead {
  int x, y, z;                    
  struct neuronHead *apical[25];  
  struct neuronHead *basal[25];    
  struct neuronHead *axon[25];      
  int time;                       
} Neuron;
Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
0

Consider creating an instance of an int:

int some_int;

In C, in general, the syntax is:

<type> <variable_name>

When you have written something like this:

struct Thing {
    int i;
    /* Other members... */
} thing;

What this actually means is: create a variable, named thing, which is of type struct Thing, and this structure is defined as follows: { int i; /* Other members... */ }.

Then you do something like this:

typedef struct thing SomeThing;

At this point, it makes no sense, as you are trying to typedef an instance (thing).

What you probably meant was something like this:

struct Thing {
    int i;
    /* Other members... */
}; /* Nothing here! It's the end of type definition. */

typedef struct Thing thing; /* Typedef "struct Thing" -> "thing". */

The general syntax for typedef is:

typedef <original_type> <new_alias>

So it can be made shorter:

typedef /* Typedef the following struct... */
    struct Thing {
        int i;
        /* Other members... */
    }
thing; /* ... to such a name. */

Then you can correctly use thing as a variable type.

Also: There are no references in C, just the pointers.

rubikonx9
  • 1,403
  • 15
  • 27
0

You should replace

typedef struct neuron Neuron;

with

typedef struct neuronHead Neuron;

When writing

struct neuronHead { ... } neuron;

you introduce two elements:

  • a compound data type named "struct neuronHead",

  • and a variable named "neuron" having type "struct neuronHead".

Typedefs allow to create aliases for data types:

typedef <original_type> <alias_type>;

while in your example an <original_type> (struct neuron) is not a proper type. Proper type definitions are both:

struct neuronHead { ... } neuron; /* data type AND variable were introduced */
typedef struct neuronHead Neuron; /* data type introduced */

and:

typedef struct neuronHead { ... } Neuron; /* data type AND type alias were introduced */

Sample usage of pre-defined types:

struct neuronHead n1; /* correct */
Neuron            n2; /* also correct */
struct neuron     n3; /* incorrect: 'neuron' is variable name! */

Thank you.