View Full Version : Why can't I chain "!" or "~" operators?
02-12-2007, 03:38 AM
I want to toggle a pin from high to low and back to high. I tried this:
And the Spin compiler doesn't like it. It also won't let me get away with:
It seems to me that that ought to work; it should be a one line equivalent to:
I would also like to be able to say:
But that doesn't work either.
Edit: Spin needs C-style preprocessor macros! My kingdom for a macro feature! Then I could just say #define TOGGLE(x) !x; !x
02-12-2007, 03:56 AM
Why do you want to put those operators together in the first place?
"There are two things that are infinate: Human Stupidity and the universe. I'm not sure about the latter." - Mark Twain
I would imagine for a brief pulse, say for latching a 595 shift register
or reseting a 6502 as his code would suggest
Who says you have to have knowledge to use it?
I've killed a fly with my bare mind.
Phil Pilgrim (PhiPi)
02-12-2007, 04:05 AM
The operators "!", "~", and "~~" return the value of the pin, during runtime, after the operation takes place. When you attempt to apply the operator again, you are telling the compiler you want to apply it to the result of the previous operation (a number) and not to the pin itself. That, of course, makes no sense to the compiler, and it flags the error.
Now, having said that, it's possible when compiling to keep track of two elements of an operation: the value and the "lvalue", where one exists. The "l" stands for "left", and relates to the "value" of a variable when it's encountered on the lefthand side of an assignment operator. The lvalue is just a reference to the original operand and not to its assigned value. Then, when a subsequent operation is performed, the compiler has to decide, based on context, whether to apply that operation to the value or to the lvalue.
Sometimes when interpretations like what you hoped for are implemented, ambiguities creep into the language's semantics. Spin's semantics have the advantage of being simple and unambiguous. And I'm sure that was done on purpose.
02-12-2007, 04:09 AM
Then just put them on different lines, if the reason its trying to be placed on on the same line is from the belief it runs faster (which it wouldn't by much), use a counter generate acurate pulses as small as 12.5ns in width.
Paul Baker (mailto:firstname.lastname@example.org)
Propeller Applications Engineer
Parallax, Inc. (http://www.parallax.com)
02-12-2007, 05:16 AM
No the timing is not important - and I realize it wouldn't be any faster. I was just trying to find a "shorthand" notation for a common task.