On 07/31/2018 10:41 PM, Lynn McGuire wrote:
> Can I make a C++ function definition that refers to itself ?
>
> For example, it would be something like this:
>
> void myfunction (int * nin, int * nocomp, double temperatures [ * nin],
> double components [ * nocomp] [ * nin])
In C++, the dimensions of arrays are required to be constant expressions
(8.3.4p1), so this isn't permitted.
This is a difference from C, where your code would be perfectly
acceptable. It would declare "components" as a Variable Length Array
(VLA). "temperatures" looks like a VLA, but any declaration of a
function parameter that looks like an array is implicitly converted into
a pointer declaration, with the length specified for that array being
ignored (unless preceded by the 'static' keyword). Thus, in C, that
declaration would be exactly equivalent to
void myfunction (int * nin, int * nocomp, double * temperatures,
double (*components) [ * nin])
> {
>
> }
>
> BTW, this is a Fortran 77 called function so everything is a pointer.
I'm curious - what part of that code gives you the impression that the
function refers to itself?
Later parameters in your parameter list refer to the value of earlier
parameters in that list - is that what you're talking about? In itself,
that's perfectly permissible because each parameter has a scope that
begins as soon as it's declarator is complete. (C6.2.1p7, C++ 3.3.3p2).
However, this particular way of using previously declared parameters in
the declarations of later parameter is permitted only in C, and not in C++.