3

I'm looking for a way to make Jalv2-like pseudo variables in C using the C18 compiler. A pseudo variable is something that acts like a variable but actually is a function.

In Jalv2, it's possible to make a pseudo variable like this:

function the_var'get() return byte is
    -- some code
end function

procedure the_var'set(byte in value) is
    -- some code
end procedure

Now one can read and write to the_var, while actually those functions are executed:

the_var = 0x40         -- actually executes the_var'set(0x40)
doSomething(the_var)   -- actually executes doSomething(the_var'get)

Is there something similar for C?

1 Answers1

3

No, it's not possible with C. It's not even possible with the preprocessor. The = operator always does the exact same thing in C, and there are no ways to customize it.

If you want to do things like that, you'll have to pick a different language. Like C++, for example, which lets you override operator = (for a setter) and operator int (for a getter).

Dietrich Epp
  • 205,541
  • 37
  • 345
  • 415