Is C99 right that you don't need to specify arguments in function pointer declarations in structures?

I wrote the following C99 code and wondered about the structure declaration. In it, I declare two function pointers that ultimately point to two push / pop methods in the main code. In function pointer declarations, I bypassed the arguments and the program compiles normally. It's right? I am sure I read that arguments should be provided. Is this the correct behavior of the C99?

#include <stdio.h>

#define INITIAL_STACK_SIZE 1000

typedef struct stack
{
    int index;
    void *stack[INITIAL_STACK_SIZE];
    void* (*Pop)(); //<-- Is this correct?
    void (*Push)(); //<-- Is this correct?
} stack;

stack CreateStack(void);
void PushStack(stack*, void *);
void *PopStack(stack*);

stack CreateStack(void)
{
    stack s = {0, '\0'};
    s.Pop = PopStack;
    s.Push = PushStack;
    return s;
}

void PushStack(stack *s, void *value)
{
    if(s->index < INITIAL_STACK_SIZE)
    {
        s->stack[s->index++] = value;
    }
    else
    {
        fputs("ERROR: Stack Overflow!\n", stderr);
    }
}

void *PopStack(stack *s)
{
    if(s->index > 0)
    {
        return s->stack[--s->index];
    }
    else
    {
        fputs("ERROR: Stack Empty!\n", stderr);
        return NULL;
    }
}

int main(int argc, char *argv[])
{
    stack s = CreateStack();

    s.Push(&s, "Hello");
    s.Push(&s, "World");

    printf("%s\n", (char*)s.Pop(&s));
    printf("%s\n", (char*)s.Pop(&s));

    return 0;
}

I tried adding arguments to function pointers, but I got a compiler error Extraneous old-style parameter list., so I assume this is correct, but will like a different opinion.

EDIT: " ", "typedef name" "stack" , struct "", , , .

Pelles C.

+5
3

GCC std=c99 -Wall -pedantic, , , . , .

, :

void* (*Pop)(struct stack*);
void (*Push)(struct stack*, void*);

GCC 4.2 .

, , , , Push . .

+2

( ). , , . , :

s.Push(arg, &s);   // oops, reverse the arguments

, .

ANSI K & R C ; , . , .

gcc -Wstrict-prototypes .

+5

gcc ( -pedantic -Wall -std=c99) :

typedef struct stack
{
 int index;
 void *stack[INITIAL_STACK_SIZE];
 void* (*Pop)(struct stack *);
 void (*Push)(struct stack *, void *);
} stack;
+1
source

All Articles