ara1
1
I am having a lot of errors from an include file inside a function.
This would lead me to believe that #includes are not allowed inside a function, but I can not find any such prohibition in the help files.
Are #include files allowed inside functions?
Ara
It is allowed but it depends on what is content of include file.
So let's say your incude file's name is _test.afl
Within that AFL there is placed a variable "x" and a value such as 1 is assigned to it.

Now... to "Formula 156.afl" of upper picture there is added a function with #include line:
function fun_name()
{
#include <_test.afl>
result = x;
return result;
}
y = fun_name();
printf( "y is: %g", y );
If applying Formula 156 then there is no error but output of y = 1
Now what if we add a function to that include file _test.afl

Then if still executing formula file "Formula 156" with same content as above then you will get error.
Why? Because it is not allowed to place a function definition within another function.
So if you do this considering content of _test.afl of upper case
function fun_name()
{
#include <_test.afl>
result = x;
return result;
}
Then it is same as doing this one
function fun_name()
{
x = 1;
function fun_name2( arg1, arg2 )
{
result = arg1 + arg2;
return result;
}
result = x;
return result;
}
and it is not allowed as well.
In general it is not good practice to add include file within function. Just avoid nightmare(s).
7 Likes