2013-04-22 37 views
3

我正在尋找一種方法,使使用C18編譯器使用C Jalv2狀的準變量。僞變量就像一個變量,但實際上是一個函數。C18僞變量

在Jalv2,有可能使這樣的僞變量:

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

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

現在可以讀取和寫入the_var,而實際上這些功能被執行:

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

有什麼類似於C?

+0

這聽起來像你所要求的在C.否「getter和setter」,這是不可能的。 – 2013-04-22 08:43:50

+0

@DietrichEpp是否有解決方法? – Keelan 2013-04-22 08:44:04

+0

當然,只是明確地調用函數。 – 2013-04-22 08:44:20

回答

3

不,這是不可能的C.它甚至不能與預處理。運算符總是在C中完成同樣的事情,並且沒有辦法對其進行自定義。

如果你想要做這樣的事情,你必須選擇一個不同的語言。例如,像C++一樣,它可以替代operator =(對於setter)和operator int(對於getter)。