@fxm,
Thanks for the Additions, Corrections etc. The Manual is getting more useful (better to understand) by the day ...
Parenthesis and macros
-
- Posts: 2958
- Joined: Jun 02, 2015 16:24
Re: Parenthesis and macros
I'm just thinking that the dereferencing operator is particularily prone to error if parenthesis are omitted. It could be taken for a multiplication:
Code: Select all
*pointer
Re: Parenthesis and macros
I don't understand that remark!
-
- Posts: 2958
- Joined: Jun 02, 2015 16:24
Re: Parenthesis and macros
I think of something like that. Of course, there is a small mistake at the origin, but multiplication sign is often omitted in math.fxm wrote:I don't understand that remark!
Code: Select all
#define x(p) *p
dim as integer p = 100
print 3 x(@p) 'error 20: Type mismatch in 'p = 3 x(@p)
print 3 * x(@p)
sleep
Re: Parenthesis and macros
Coding Math. vs. writing Math. (as in: write a Formula on Paper) are Worlds apart!Tourist Trap wrote:... but multiplication sign is often omitted in math.
The code line you're referring to, simply doesn't make any sense to the Compiler.
And the Macro Body has to be enclosed in Parenthesis to work as expected (Ptr deref.).
Working code:
Code: Select all
#define x(p) (*p)
dim as Long p = 100
print 3 - x(@p)
print 3 + x(@p)
print 3 * x(@p)
print 3 / x(@p)
sleep
-
- Posts: 2958
- Joined: Jun 02, 2015 16:24
Re: Parenthesis and macros
Not for all the softwares I use. Some of them just remove multiplication sign for me. However this seems that macros are not doing no check at all. Some syntax is still required. This is not only text replacement tool, that's what I neglicted.MrSwiss wrote: Coding Math. vs. writing Math. (as in: write a Formula on Paper) are Worlds apart