Last example for rule #13.6?

Moderators: misra-c, david ward

Post Reply
gs
Posts: 87
Joined: Thu Nov 18, 2004 1:39 am

Last example for rule #13.6?

Post by gs » Mon Oct 28, 2013 5:55 pm

Try as I might, I cannot get my compiler to recognize the last example for rule #13.6, the example involving an array of function pointers, as well formed. Is this intended?

misra-c
Posts: 566
Joined: Thu Jan 05, 2006 1:11 pm

Re: Last example for rule #13.6?

Post by misra-c » Thu Dec 12, 2013 9:11 am

The example should compile with a conformant C99 compiler.

However, trying the following in http://www.cdecl.org might help some readers to understand the declaration.

void (*fn)(int) declares fn as pointer to function (int) returning void

void (*fn)(int[5]) declares fn as pointer to function (array 5 of int) returning void

void (*fn[3])(int[5]) declares fn as array 3 of pointer to function (array 5 of int) returning void

so "typedef void (*fntype[3])(int[5]);" would declare a type called fntype which was an "array 3 of pointer to function (array 5 of int)".

You can omit the type name when using the type as a parameter to a function or in sizeof, and also you can independently add/omit a parameter name. Using a parameter name "a", this example would give you:
void (*[3])(int a[5])

In the document example the [3] and [5] are replaced by two variable length arrays [n] and [v] respectively.
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.13 Side effects”