Post Reply 
forward declaration of variables?
10-12-2015, 01:28 AM (This post was last modified: 10-12-2015 01:31 AM by ji3m.)
Post: #1
forward declaration of variables?
So to connect functions between files we use the forward declaration

myfun (); if my fun is in another file. This is good.

But this doesnt work with variables or pseudo constants

If myvar was in another file and we use it here, just hope the other was compiled first.

the declaration myvar; produces a new local to the current file.

This is wrong.

it should work the same way. If a local is desired it should be declared as
local myvar;

So the upshot is if variables are to be shared between files they better all be declared in
a file that is compiled before everyone else or an endless stream of errors occurs.

It seems like ppl is uninventing well understood rules of scope.

I work with android Prime only for now on my
Galaxy Tab Pro/Note 2
Find all posts by this user
Quote this message in a reply
10-12-2015, 04:12 AM
Post: #2
RE: forward declaration of variables?
(10-12-2015 01:28 AM)ji3m Wrote:  So to connect functions between files we use the forward declaration

myfun (); if my fun is in another file. This is good.

But this doesnt work with variables or pseudo constants

If myvar was in another file and we use it here, just hope the other was compiled first.

the declaration myvar; produces a new local to the current file.

This is wrong.

it should work the same way. If a local is desired it should be declared as
local myvar;

So the upshot is if variables are to be shared between files they better all be declared in
a file that is compiled before everyone else or an endless stream of errors occurs.

It seems like ppl is uninventing well understood rules of scope.

Here's how I understand the scope:

http://www.hpmuseum.org/forum/thread-215.html

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
10-12-2015, 05:29 AM
Post: #3
RE: forward declaration of variables?
Hello,

>It seems like ppl is uninventing well understood rules of scope.

No, all languages have their own rules for scope, and PPL has its own, slightly different, to adapt to the calculator case and system.

PPL recognizes 3 types of scope:
1) The system scope, which is anything that is already recognized by the system (ie, you can go to home or cas, type it, and it does something).
2) The current file or program scope (these are the same as 1 file is 1 program for PPL)
3) The current function scope

Notes:

1 can contain a number of USER defines objects, such as vars and functions from OTHER programs

2 At program scope level, you find program global variables. EXPORTED, or not (LOCAL) and program functions, once again, EXPORTED or not
Here LOCAL, if used means: Not exported. Probably a bad choice as local is also used in function.
Here you will also find forward declarations, but this is just a compilation trick to allow you to do double recursive functions. This is NOT designed to be like a C "function declaration".

3 at function scope, you find all the function local variables (including the parameters).


See, the PPL scope is well defined, BUT it is more complex that C or similar scope due to the fact that PPL programs execute, and are part of, the glogal calculator system.

Cyrille

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
Find all posts by this user
Quote this message in a reply
10-12-2015, 12:59 PM
Post: #4
RE: forward declaration of variables?
Thanks again. Once again ive been bitten by trying to develop a large app with small files. All my recent problems and questions are related to this. I realize now that it was a bad idea since it makes all my functions and variable global whick is not at all desireable. I got away with scope murder from day one since the order of compilation saved me. But now it is critical. I really did this since constantly copy /paste of a large file made it very hard to find errors. I should probably move to a single file now. BTW the android prime crashes frequentl and randomly but mosgly during compilation. It does it a lot when a program reference an external function which is not declared or a varible not already compiled. Dangling references?

I work with android Prime only for now on my
Galaxy Tab Pro/Note 2
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)