News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Layout

Started by Ivano, Aug 06, 2022, 01:17 PM

Previous topic - Next topic

Ivano

Good morning,
in the layout of the programs I have always used subroutines and procedures first and lastly the main program as on proton compiler manual.
Now I see on the positron compiler manual the layout has changed with the subroutines at the end.
Is there a difference? What is better?
Thank you

John Drew

Hello Ivano,
I think it's largely personal preference. Having grown up with Pascal I prefer Main at the end. With projects I usually have an Initialise label which flows into the Main and from thereon the Initialise is disregarded. I have a GOTO Initialise as the first bit of code.
By having Main at the end I put my Include files at the beginning where I can see them but after the Goto Initialise instruction so they are jumped over. I reckon it looks neater that way.
The position of Procedures doesn't matter because the Compiler gathers them up, checks if they are used and effectively puts the called procedures at the end of the code and ignores those that are not. All part of Les's cunning method of gaining efficiency for us users.
John

Ivano

I put pic, freq, config, variables, includes, interrupt, ... goto main before the procedures and subroutines and main at the end.
Include can I leave it before goto main as I always have?
Thank you

keytapper

These are personal preferences. Just keep in mind where the assembly will jump to. I had some hold program that behaved differently in a new compiling.
I prefer to get main to the beginning and verify that nothing is getting run prior that point. Even the Dim with assignment should go to main. The last is the ISR. After the main loop there are my procedures and subroutines.
Well, I should get used to write procedures only. Basically are the same style, but no returning result.
Ignorance comes with a cost

Ivano

Thanks to all for the info