gcc/ChangeLog:

        * doc/extend.texi (Array Parameters): New node.

Signed-off-by: Alejandro Colomar <[email protected]>
---
 gcc/doc/extend.texi | 57 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index b4879b3d82ff..d4905af4ba5f 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -604,6 +604,7 @@ GCC supports several extensions relating to array, union, 
and struct types,
 including extensions for aggregate initializers for objects of these types.
 
 @menu
+* Array Parameters::    Function parameters declared with array type.
 * Variable Length::     Arrays whose length is computed at run time.
 * Zero Length::         Zero-length arrays.
 * Empty Structures::    Structures with no members.
@@ -618,6 +619,62 @@ including extensions for aggregate initializers for 
objects of these types.
 * Designated Inits::    Labeling elements of initializers.
 @end menu
 
+@node Array Parameters
+@subsection Array Parameters
+@cindex array parameters
+
+Array parameters are adjusted to pointers.
+
+ISO C ignores the length of array parameters.
+However,
+GCC extends the language so that
+the length of array parameters is meaningful.
+
+For a function declared as
+
+@smallexample
+void f (int n, int a[n]);
+@end smallexample
+
+A caller must provide a pointer to at least @code{n} elements
+or a null pointer.
+
+The function must not access more than @code{n} elements,
+if it is a valid pointer.
+
+Type compatibility rules are also extended
+to take this length into account.
+For the purpose of compatibility,
+a first-level pointer and an array of unspecified length
+are considered equivalent.
+
+As an example,
+the following pairs of declarations are compatible:
+
+@smallexample
+void f (int n, int a[n]);
+void f (int n, int a[*]);
+
+void g (int a[2]);
+void g (int a[*]);
+
+void h (int a[2]);
+void h (int *a);
+@end smallexample
+
+But the following pairs are incompatible:
+
+@smallexample
+void i (int n, int a[n]);
+void i (int n, int a[2]);
+
+void j (int n, int a[n]);
+void j (int n, int a[n + 1]);
+@end smallexample
+
+Violations of these rules are diagnosed when possible,
+as part of @code{-Warray-parameter=}.
+
 @node Variable Length
 @subsection Arrays of Variable Length
 @cindex variable-length arrays
-- 
2.51.0

Reply via email to