I recently found a bug in some legacy code that amounts to the following:
macro junk() variable a=1, b=1, c=3, d=4
if(a!=b)||(c!=d)// should be ((a!=b) || (c!=d)) print"not equal" else print"both equal" endif end
I realize that macros aren't compiled but are interpreted line by line. But I thought Igor would throw an error as it tried to execute the if statement because of the trailing text after the first ). But it doesn't, and prints "both equal". Changing the macro to a function does produce an error at compile time.
One of the reasons to use user-defined functions. The error checking is much better and happens at compile time, not at run time. In general, enhancements to the Igor language go only into functions.
I recently found a bug in some legacy code that amounts to the following:
variable a=1, b=1, c=3, d=4
if (a!=b) || (c!=d) // should be ((a!=b) || (c!=d))
print "not equal"
else
print "both equal"
endif
end
I realize that macros aren't compiled but are interpreted line by line. But I thought Igor would throw an error as it tried to execute the if statement because of the trailing text after the first ). But it doesn't, and prints "both equal". Changing the macro to a function does produce an error at compile time.
This is true for Igor 7&8.
September 25, 2018 at 02:48 pm - Permalink
One of the reasons to use user-defined functions. The error checking is much better and happens at compile time, not at run time. In general, enhancements to the Igor language go only into functions.
September 26, 2018 at 11:11 am - Permalink