I'm trying to maintain a library of code, with samples, for multiple embedded platforms. I need to support the concept of "far" (non 16-bit) pointers for some function parameters.
I thought I had a good solution with defining the macro FAR to be __far on some platforms and nothing on platforms with 32-bit pointers (embedded Linux, Win32, etc.). With that macro, I could easily define pointers as somestruct_t FAR *foo.
But then I started working with Freescale processors, and their compiler requires the FAR to go between the asterisk and variable name. (somestruct_t * __far foo).
The best solution I've come up with to handle this case is to define a macro FARPTR as either __far *, * __far or just * depending on the platform. This allows for somestruct_t FARPTR foo.
Are there cleaner solutions out there? In particular, I don't like that there isn't a * visible to someone reading that code. I'm also worried that I will run into problems when it comes to function declarations. Get a load of this syntax from the Freescale compiler help:
int __far *f(); // __far function returning a pointer to int
int * __far f(); // Function returning a __far pointer to int
int __near * __far f(); // __near function returning a __far pointer to int
That last one kills me -- a qualifier inside of the return type indicates a near function?! And I've recently learned that adding the __near isn't enough to actually compile a function to near memory -- I need to wrap it in pragmas.
So, has anyone seen a nicer solution than my FARPTR macro idea?
constworks with pointers, with__nearmirroring C++'smutable. It doesn't seem very alien to me. - Fred FooFARto__far(and similar forNEAR) still work? You just have to make sure theFAR/NEARgo where the Freescale compiler wants them (like it or not). On other platforms those macros will be whitespace, so where they're used in the declarations is of no concern for them. - Michael Burr__farbefore*and some that require it after. - tomlogic