Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C18 pseudo variables

Tags:

c

pic

mplab-c18

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 Answers

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).

like image 60
Dietrich Epp Avatar answered Jun 28 '26 20:06

Dietrich Epp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!