Hi All,
I am currently porting a large amount of C API's and apps to FreeBASIC and have decided to organize the code as one large file to be compiled by utilizing the second method of 'Manage[ing] Reusable Procedures by Including Source vs Compiled Modules' (https://www.freebasic.net/wiki/ProPgSou ... iledModule). I am trying to implement private subs and functions as well as private var (by private, I mean local to the module code only).
Is there a way of implementing these items with a module only scope when everything is in one file (in memory) during compilation?
TIA
Module Global Subs and Functions and Module Vars Using Second Method of Manage Reusable Procedures
Re: Module Global Subs and Functions and Module Vars Using Second Method of Manage Reusable Procedures
NAMESPACEs allow to group entities like objects (predefined data-types and UDTs including Union and Enum) and procedures (including their declarations) under a name. This way the global scope can be divided in "sub-scopes", each one with its own name.
Each include module file has its own NAMESPACE scope with a specific name. If a main code body exists in a module file, put it in a SCOPE...END SCOPE block with its other non-static local variables, and use not USING(Namespaces) but the full path to access its NAMESPACE scope.
Purely academic example (with identical symbol names, each in its own scope):
- module1.bi:
- module2.bi:
- module.bas:
Each include module file has its own NAMESPACE scope with a specific name. If a main code body exists in a module file, put it in a SCOPE...END SCOPE block with its other non-static local variables, and use not USING(Namespaces) but the full path to access its NAMESPACE scope.
Purely academic example (with identical symbol names, each in its own scope):
- module1.bi:
Code: Select all
Namespace module1
Type UDT
Dim As String s = "module1"
End Type
Sub printMyName(Byref u As UDT)
Print u.s
End Sub
End Namespace
' if main code body exists in module file
Scope
Dim As module1.UDT u
module1.printMyName(u)
End Scope
Code: Select all
Namespace module2
Type UDT
Dim As String s = "module2"
End Type
Sub printMyName(Byref u As UDT)
Print u.s
End Sub
End Namespace
' if main code body exists in module file
Scope
Dim As module2.UDT u
module2.printMyName(u)
End Scope
Code: Select all
#include "module1.bi"
#include "module2.bi"
Print
Dim As module1.UDT u1
module1.printMyName(u1)
Dim As module2.UDT u2
module2.printMyName(u2)
Sleep
Last edited by fxm on Jul 03, 2024 18:31, edited 3 times in total.
Reason: Completed descriptive and added example.
Reason: Completed descriptive and added example.