Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it correct C99 that you don't need to specify arguments in function pointer declarations in structs?
    text
    copied!<p>I have written the following C99 code and was wondering about the struct declaration. In it i declare two function pointers which ultimately point to the two push/pop methods in the main code. In the function pointer declarations i've ommited the arguments and the program compiles ok. Is this correct? I'm sure i've read that the arguments must be supplied. Is this correct C99 behaviour?</p> <pre><code>#include &lt;stdio.h&gt; #define INITIAL_STACK_SIZE 1000 typedef struct stack { int index; void *stack[INITIAL_STACK_SIZE]; void* (*Pop)(); //&lt;-- Is this correct? void (*Push)(); //&lt;-- 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-&gt;index &lt; INITIAL_STACK_SIZE) { s-&gt;stack[s-&gt;index++] = value; } else { fputs("ERROR: Stack Overflow!\n", stderr); } } void *PopStack(stack *s) { if(s-&gt;index &gt; 0) { return s-&gt;stack[--s-&gt;index]; } else { fputs("ERROR: Stack Empty!\n", stderr); return NULL; } } int main(int argc, char *argv[]) { stack s = CreateStack(); s.Push(&amp;s, "Hello"); s.Push(&amp;s, "World"); printf("%s\n", (char*)s.Pop(&amp;s)); printf("%s\n", (char*)s.Pop(&amp;s)); return 0; } </code></pre> <p>I tried adding the arguments to the function pointers but i got a compiler error of <code>Extraneous old-style parameter list.</code> so i'm guessing it's correct, but would love another opinion.</p> <p>EDIT: I was experiencing the above 'Extraneous old-style parameter list' error because i was using the typedef name 'stack' rather than using the struct keyword with 'stack' to define it was the structure i am currently defining.</p> <p>I'm using the <a href="http://www.smorgasbordet.com/pellesc/" rel="nofollow noreferrer">Pelles C</a> compiler.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload