Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Last example for rule #13.6?
#1
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?
Reply
#2
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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)