#include<stdio.h>
#include<stdlib.h>
#define GREY 1
#define BLACK 0
#define WHITE 2
typedef struct node * graph;
typedef struct stack * snode;
extern int stack_counter;
graph cnode(int data);          //cnode is to create a node for graph
void cgraph(void);
struct node {
        int data, color;
        struct node *LEFT, *RIGHT, *TOP, *DOWN;
};//this structure defines a node of the graph

struct stack {
struct stack *priv;
struct cgraph *graph_node;
};// this is to define a structure which should hold node of a structure

extern snode sroot;

I defined a header file (declaration.h) as above and following is a c program(stack.c)

#include<declarations.h>
void cstack (graph temp);
void stackpush(snode stemp);
 stack_counter = 0;
 
sroot=NULL;
void cstack (graph gtemp) //cstack is to create stack
{
   snode spriv,some;
  if (stack_counter==0)
  {
   sroot=cstacknode(gtemp);
    spriv=sroot;
   stack_counter++;
   }
   else{
   some=cstacknode(gtemp);
    some->priv=spriv;
    spriv=some; 
  } 
 
}

//struct stack is representing a stack
//struct node is representing a node in graph

snode  cstacknode (graph gtemp) 
//this function should create a node of the stack which should be storing the graph node as a pointer
{
 snode an;
 an=(snode)malloc(sizeof(snode));
 an->graph_node=gtemp; 
 an->priv=NULL;
 return an;
}

void stackpush(snode stemp)
{

}

I am making which would be used in the library I am developing


both the above files are in same directory.
I compiled the above file stack.c as

cc -I ./ stack.c

and got following warnings

stack.c:4: warning: data definition has no type or storage class
stack.c:6: warning: data definition has no type or storage class
stack.c:6: error: conflicting types for ‘sroot’
./declarations.h:21: note: previous declaration of ‘sroot’ was here
stack.c:6: warning: initialization makes integer from pointer without a cast
stack.c: In function ‘cstack’:
stack.c:13: warning: assignment makes pointer from integer without a cast
stack.c:17: warning: assignment makes pointer from integer without a cast
stack.c: At top level:
stack.c:27: error: conflicting types for ‘cstacknode’
stack.c:12: note: previous implicit declaration of ‘cstacknode’ was here
stack.c: In function ‘cstacknode’:
stack.c:32: warning: assignment from incompatible pointer type

from this set of warnings I want to understand following warnings

stack.c:4: warning: data definition has no type or storage class
stack.c:6: warning: data definition has no type or storage class

The above warning is coming from file stack.c
and line 4 and 6 in stack.c have

stack_counter = 0;

sroot=NULL;

and both the above variables I have defined in declarations.h so why do I get the above warning ?

because your added extern

extern int stack_counter;
extern snode sroot;

This informs the linker that both of these are defined elsewhere.

Edited 6 Years Ago by gerard4143: n/a

because your added extern

extern int stack_counter;
extern snode sroot;

This informs the linker that both of these are defined elsewhere.

Actually no. It's because the variables are initialized outside any function and without any data type specifier (which is why the compiler says "data definition has no type").

This article has been dead for over six months. Start a new discussion instead.