0

I'm trying to implement stack in C and it got the weird error in my MinGw compiler

 gcc -Wall -o stack stack.c 

Stack.c

#include "stack.h"
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>


Stack *create(int size) {
    Stack *result;
    result = (Stack *) malloc(  sizeof(Stack) * size );
    assert(result != NULL);

    result -> file = result;
    result -> maxAllocate = size;
    result -> top = -1;
    return result;
}

stack.h

#define MAX_SIZE 1024

typedef struct {
    void **file;    
    int top;     
    int maxAllocate; // current size of array allocated for stack
} Stack;

Stack *create(int size);        
int   push(Stack *s, void *x);  
void  *pop(Stack *s);           
int   isEmpty(Stack *s);        

error

C:\test>gcc -Wall -o stack stack.c
stack.c: In function 'create':
stack.c:26:17: warning: assignment from incompatible pointer type [enabled by de
fault]
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../libmingw32.a(main.o): In function
 `main':
C:\MinGW\msys\1.0\src\mingwrt/../mingw/main.c:73: undefined reference to `WinMai
n@16'
collect2: ld returned 1 exit status
8
  • 11
    What's the error? Commented Mar 12, 2014 at 12:41
  • Please provide error you have got Commented Mar 12, 2014 at 12:45
  • 3
    result -> file = result; looks like incorrect, should be result -> file = &result; Commented Mar 12, 2014 at 12:45
  • yes updated with error, sorry about that Commented Mar 12, 2014 at 12:48
  • 3
    warning here but error in main.c where is main? Commented Mar 12, 2014 at 12:51

2 Answers 2

3

With gcc -Wall -o stack stack.c you compile only stack.c (which has o main function in it) but for a functioning application you will also need a main function, as the main entry point: http://en.wikipedia.org/wiki/Entry_point

Sign up to request clarification or add additional context in comments.

Comments

2

using gcc with -o option means you want to compile, link and run your program (this command won't run it, but usually that's the reason with such usage). You cannot run a program without an entry point (in this case it's main function).

If you only want to check if your stack.c compiles use gcc -Wall -c stack.c.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.