fpco / inline-c

284 stars 50 forks source link

Please clarify Ptr usage on left side of equals. #91

Closed YellowOnion closed 5 years ago

YellowOnion commented 5 years ago

I'm trying to use alloca to capture some values. ` alloca $ \x -> [C.exp| $(int *x) = 3]

peek x the c code should be *x = 3;` how do I reproduce this?

peeking x causes a me to get junk data and not 3.

facundominguez commented 5 years ago

Maybe alloca $ \x -> [C.exp| *$(int *x) = 3] >> peek x ?

bitonic commented 5 years ago

What @facundominguez said -- the anti-quotation brings into scope a variable of type int *, and then you need to modify its value as usual. The * inside the anti quotation is just indicating the type, it doesn't dereference the value itself.