> I have no Arduino experience, but from what I've been reading, it > appears that in their ecosystem you can define multiple instances of a > class. So in my case if I made one routine that dealt with a single > encoder, I could create 2 instances to deal with 2 encoders, etc. As > far as I understand it, I can't do that in straight C I have not seen the original library you use and obviously a C++ is much more than this, but perhaps you can try to create a structure to store your data (as your instance variables) and use bunch of functions that can deal with these struct elements... Now all you have to do is to occupy memory for the struct and give it's pointer to your functions (C++ does exactly that in the background, the pointer is called "this"). So a method without any parameters looks like this: myMethod( struct myStruct * this ); With one parameter: myMethod( struct myStruct * this, char * str ); etc... Obviously a C++ compiler is lot more complex than this, you have to implement your very own function name mangling as ANSI C would not handle usage of same C functions declared with different return type or parameter list. For example the "myMethod" was already used in the no-parameter example, therefore you should declare: myMethod_s_( struct myStruct * this, char * str ); myMethod_i_( struct myStruct * this, int myInt ); myMethod_u_i_( struct myStruct * this, unsigned myUnsigned, int myInt ); etc etc etc... Alternatively you can try to compile C++ to C using LLVM, I have never tried it, just read it somewhere it might be possible. Tamas On 19 March 2015 at 10:21, Josh Koffman wrote: > Hi all, > > So as you may have guessed, I'm working on some rotary encoder routines i= n > XC8. > > I've been looking around, and I've actually found a pretty neat > Arduino library. It handles the encoder, acceleration (values change > faster if you spin faster), encoder switch status (click, double > click, held, etc). I'm considering trying to port it to XC8 as I think > it would be useful, but also a really good exercise in coding. > > I have no Arduino experience, but from what I've been reading, it > appears that in their ecosystem you can define multiple instances of a > class. So in my case if I made one routine that dealt with a single > encoder, I could create 2 instances to deal with 2 encoders, etc. As > far as I understand it, I can't do that in straight C. > > So, what is the preferred way of dealing with this? I could make the > original function deal with total number of encoders that I have. Or I > could make multiple copies of a function that dealt with a single > encoder. In both cases I'll need to deal with variables carefully. > > Is there another (possibly better) way? I'm interested in this in the > abstract as eventually I will likely run into this situation with > other routines (switch debounce, for instance). > > Thanks! > > Josh > -- > A common mistake that people make when trying to design something > completely foolproof is to underestimate the ingenuity of complete > fools. > -Douglas Adams > -- > http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > --=20 int main() { char *a,*s,*q; printf(s=3D"int main() { char *a,*s,*q; printf(s=3D%s%s%s, q=3D%s%s%s%s,s,q,q,a=3D%s%s%s%s,q,q,q,a,a,q); }", q=3D"\"",s,q,q,a=3D"\\",q,q,q,a,a,q); } --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .