Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use typedef in c?

Tags:

c

struct

typedef

Can anybody tell me when to use typedef in C? In the following code I get a warning by gcc :

warning: useless storage class specifier in empty declaration

typedef struct node
{
  int data;
  struct node* forwardLink;
} ;
like image 786
damned Avatar asked Oct 15 '12 16:10

damned


Video Answer


1 Answers

The syntax of typedef is typedef <type> <name>; it makes the type accessible through the name. In this case, you've only specified a type, and no name, so your compiler complains.

You probably want

typedef struct node
{
  int data;
  struct node* forwardLink;
} node;
like image 110
nneonneo Avatar answered Sep 21 '22 06:09

nneonneo