0
typedef int (*t_built)(t_cmds *, t_table *);

struct cmdline
{
   char *      reserved[7]; /* "echo pwd cd unset export exit env" */
   t_built     builtin[7];
}

How can I store my builtin functions into builtin array with same indexes as in reserved array. Can you help me to understand how this syntax works and for what declared typedef for function pointer.

1
  • IMO, It is easier to understand function type rather function pointer type was typedef-ed. typedef int t_build(t_cmds*, t_table*); t_build *builtin[7];. Commented Nov 17, 2022 at 12:46

1 Answer 1

1

Let's decompose the declarations:

int f(int);

declares f as a function taking an int and returning an int.

This can be written with parentheses (this is useless here but harmless):

int (f)(int);

The following declaration:

int *f(int);

declares f as a function taking an int and returning a pointer to an int.

This time, parentheses change the order of evaluation:

int (*f)(int);

declares f as a pointer to a function taking an int and returning an int.

typedef is used to define a type instead of a variable.

Finally the sequence:

typedef int (*f)(int);
f a[7];

declares a as an array of seven elements of type f, f describing a pointer to a function taking an int and returning an int.

By the way, there is a converter for that sort of things: cdecl: C gibberish ↔ English.

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

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.