Compiler is not able to differenciate external variables neither constants from a macro local ones.
I suggested a way to fix it:
Will you fix it?Make obligatory the '#' postfix for Macro input params
Will you fix it?Make obligatory the '#' postfix for Macro input params
That's no good idea, and it has been told you years ago.Psychophanta wrote:I suggested a way to fix it:Make obligatory the '#' postfix for Macro input params
It seems that you really like to beat dead horses ...Psychophanta wrote:Will you fix it?
Sorry to have to correct that:Little John wrote: That's no good idea, and it has been told you years ago.
There's no need to discuss that further: Everyone who is interested can read her/himself what has been written in this thread more than 6-7 years ago.Psychophanta wrote:Sorry to have to correct that:
Agree, but repeat with the fact, and don't try to escape from reality, just like german people is in use to do again and again:Little John wrote:There's no need to discuss that further: Everyone who is interested can read her/himself what has been written in this thread more than 6-7 years ago.Psychophanta wrote:Sorry to have to correct that:
Psychophanta wrote:...no solution to differenciate external variable names from input parameters names for macros.
Exactly. There is no confusion with this:Demivec wrote:Use a different name.Psychophanta wrote:...no solution to differenciate external variable names from input parameters names for macros.
Code: Select all
Define .f
v=1.0
Macro ma(Macro_ma_Parameter_v=2.0)
Debug Pow(Macro_ma_Parameter_v,v)
EndMacro
ma()
A simple technique is to habitually prefix an underscore (or "InsertYourFavoritePrefixHere") to all macro parms:Demivec wrote:Use a different name.
Code: Select all
Define .f
v=1.0
Macro ma(_v=2.0)
Debug Pow(_v,v)
EndMacro
ma()
You really made my day. I'm so sorry that I can't confirm your prejudices.Psychophanta wrote:don't try to escape from reality, just like german people is in use to do again and again:
Huh, really? Oh what a big problem!Psychophanta wrote:no solution to differenciate external variable names from input parameters names for macros.
I've suggested the same thing to him more than 6 years ago.Tenaja wrote:A simple technique is to habitually prefix an underscore (or "InsertYourFavoritePrefixHere") to all macro parms:Demivec wrote:Use a different name.
You did actually not understand the replies that you got 6-7 years ago, among others from Fred and Freak.Psychophanta wrote:A problem which a good and elegant compiler like PB is, should solve.
Mmm... allow me to remember....Little John wrote:You did actually not understand the replies that you got 6-7 years ago, among others from Fred and Freak.Psychophanta wrote:A problem which a good and elegant compiler like PB is, should solve.
Sorry, I can't help you.
Never mind if i are the only one who do that (I am not really), it is irrelevant.freak wrote:You are the only one i have seen putting a # behind every macro parameter.
I think it is a very weird thing to do (as the # is the concatination operator for macros, not a parameter postfix)
I don't think this is a good idea.
ugly ! ¿?Fred wrote:It's way too ugly ! Don't mess with global var in your macro..
We know it, thanks for remember it anyway.Fred wrote:# is already used in the macros to join 2 parameters together.
Yeah, just like procedures. Makes perfect sense... o_o :freak wrote:I don't see the problem really. It is just like with procedures.
In procedures, if you reuse a global variable (not as a parameter and without protected),
you are referencing the global variable. Same thing happens with macros.
In a procedure, if you reuse the global variable name inside a procedure as a parameter
or with protected, it will not use the global one, and you have actually no more a way
to access the global variable from inside this procedure (as the name represents the local variable then)
The same thing is with macro parameters that have the same name as a variable used elsewhere. makes perfect sense.
You always have to make sure you do not reuse the same name for different purposes.
That is a problem that exists in every language, not just in PB macros.
You can't just name all your global variables "var" and expect to get no conflict.
Choosing descriptive names solves this problem easily.
Code: Select all
Structure stru
var1.f
var2.l
EndStructure
Global v.stru
v\var2=4
var2.l=5
Procedure ma(var2=6)
Debug v.stru\var2
EndProcedure
ma()
Code: Select all
Structure stru
var1.f
var2.l
EndStructure
Global v.stru
v\var2=4
var2.l=5
Macro ma(var2=6)
Debug v.stru\var2
EndMacro
ma()
Code: Select all
#Colorhilo2=$AAEE90
Global .f a=12,b=12,c=11,e=3
Global fasehilo1.u=0,fasehilo2.u
Macro seno(f=0,desv=0)
Sin(f#+e*x/c)
EndMacro
Macro dibuja2(h,c)
For x.u=0 To 2
y.f = Sin(fasehilo#h#+e*x/c)
Debug y
y.f = seno(fasehilo#h#)
Debug y
Debug "-----------------"
Next
EndMacro
dibuja2(2,#Colorhilo2)
Code: Select all
;-----------------------------------------------
;
; Macro 1 : QQ double quote character used in macro creation
;
;
Macro QQ
"
EndMacro
;
;-----------------------------------------------
;
; Macro 2 : QQColon colon character used in macro creation
;
;
Macro QQColon
:
EndMacro
;
;-----------------------------------------------
;
; Macro 3 : QQJoin join parameter strings for macro creation
;
; bvsP1 16725 : PB macro parameter: 1
; bvsP2 16726 : PB macro parameter: 2
; bvsP3 16727 : PB macro parameter: 3
; bvsP4 16728 : PB macro parameter: 4
; bvsP5 16729 : PB macro parameter: 5
; bvsP6 16730 : PB macro parameter: 6
; bvsP7 16731 : PB macro parameter: 7
; bvsP8 16732 : PB macro parameter: 8
;
Macro QQJoin (bvsP1, bvsP2=, bvsP3=, bvsP4=, bvsP5=, bvsP6=, bvsP7=, bvsP8=)
bvsP1#bvsP2#bvsP3#bvsP4#bvsP5#bvsP6#bvsP7#bvsP8
EndMacro
;
;-----------------------------------------------
;
; Macro 4 : CreateBlockName create the QQBlock macro
;
; bvsBlockName 16663 : the name of a class or module
;
Macro CreateBlockName (bvsBlockName)
QQJoin (Macro QQBlock, QQColon, bvsBlockName, QQColon, EndMacro)
EndMacro
;
;-----------------------------------------------
;
; Macro 5 : DestroyBlockName destroy the QQBlock macro
;
;
Macro DestroyBlockName
QQJoin (UndefineMacro Q, QBlock)
EndMacro
;
;-----------------------------------------------
;
; Macro 6 : CreateLibraryName create the QQLib macro
;
; bvsLibName 16505 : the name of a dynamic library
;
Macro CreateLibraryName (bvsLibName)
QQJoin (Macro QQLib, QQColon, bvsLibName, QQColon, EndMacro)
EndMacro
;
;-----------------------------------------------
;
; Macro 7 : DestroyLibraryName destroy the QQLib macro
;
;
Macro DestroyLibraryName
QQJoin (UndefineMacro Q, QLib)
EndMacro
;
;-----------------------------------------------
;
; Macro 8 : AttachDynamicLibrary attach a dynamic library to the program
;
; bvsLibName 16505 : the name of a dynamic library
;
Macro AttachDynamicLibrary (bvsLibName)
Global lib#bvsLibName.typInt32
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
lib#bvsLibName = OpenLibrary(#PB_Any, QQ./lib#bvsLibName.so#QQ)
If IsFalse(lib#bvsLibName)
MessageRequester("Critical Error", QQ#Dynamic Library not found -- lib#bvsLibName.so#QQ, #PB_MessageRequester_Ok)
End
EndIf
CompilerCase #PB_OS_Windows
lib#bvsLibName = OpenLibrary(#PB_Any, QQ#bvsLibName.dll#QQ)
If IsFalse(lib#bvsLibName)
MessageRequester("Critical Error", QQ#Dynamic Library not found -- bvsLibName.dll#QQ, #PB_MessageRequester_Ok)
End
EndIf
CompilerCase #PB_OS_MacOS
????
CompilerCase #PB_OS_AmigaOS
????
CompilerEndSelect
EndMacro
;
;-----------------------------------------------
;
; Macro 9 : DetachDynamicLibrary detach a dynamic library from the program
;
; bvsLibName 16505 : the name of a dynamic library
;
Macro DetachDynamicLibrary (bvsLibName)
CloseLibrary(lib#bvsLibName)
EndMacro
;
;-----------------------------------------------
;
; Macro 10 : BeginLibraryDeclare link the program to dynamic library procedures
;
; bvsLibName 16505 : the name of a dynamic library
;
Macro BeginLibraryDeclare (bvsLibName)
CreateLibraryName(bvsLibName)
EndMacro
;
;-----------------------------------------------
;
; Macro 11 : EndLibraryDeclare end declares for a dynamic library
;
;
Macro EndLibraryDeclare
DestroyLibraryName
EndMacro
;
;-----------------------------------------------
;
; Macro 12 : FunctionPrototype dynamic library prototype: function
;
; bvsProcName 15157 : name of the proc being generated
; bvsDataParmType 15080 : parameter data type
;
Macro FunctionPrototype (bvsProcName, bvsDataParmType)
Prototype.bvsDataParmType QQLib#bvsProcName
EndMacro
;
;-----------------------------------------------
;
; Macro 13 : SubroutinePrototype dynamic library prototype: subroutine
;
; bvsProcName 15157 : name of the proc being generated
;
Macro SubroutinePrototype (bvsProcName)
Prototype QQLib#bvsProcName
EndMacro
;
;-----------------------------------------------
;
; Macro 14 : CreateFunctionReference create a reference to a library function
;
; bvsProcName 15157 : name of the proc being generated
;
Macro CreateFunctionReference (bvsProcName)
Global lib#QQLib#_fun#bvsProcName.QQLib#bvsProcName = GetFunction(lib#QQLib, QQ#QQLib#bvsProcName#QQ)
EndMacro
;
;-----------------------------------------------
;
; Macro 15 : CreateSubroutineReference create a reference to a library subroutine
;
; bvsProcName 15157 : name of the proc being generated
;
Macro CreateSubroutineReference (bvsProcName)
Global lib#QQLib#_sub#bvsProcName.QQLib#bvsProcName = GetFunction(lib#QQLib, QQ#QQLib#bvsProcName#QQ)
EndMacro
;
;-----------------------------------------------
;
; Macro 16 : LibCall call a dynamic library subroutine
;
; bvsLibName 16505 : the name of a dynamic library
; bvsProcName 15157 : name of the proc being generated
;
Macro LibCall (bvsLibName, bvsProcName)
lib#bvsLibName#_sub#bvsProcName
EndMacro
;
;-----------------------------------------------
;
; Macro 17 : LibReturn return a value from a dynamic library function
;
; bvsLibName 16505 : the name of a dynamic library
; bvsProcName 15157 : name of the proc being generated
;
Macro LibReturn (bvsLibName, bvsProcName)
lib#bvsLibName#_fun#bvsProcName
EndMacro
;