rhinoceroshead wrote:
Yes, the C has suddenly become poorly written :smileyhappy:
Seriously, what did you have to change to get it to compile? There are 3 pushes to the stack that happen at the beginning of the ISR and 3 pulls at the end that seem to serve no purpose. The rest of it is bloated and messy for sure. I'm not impressed.
Specifically, poorly written for
current compiler.
Welcome to the world of multiple C compilers. Each has it's own personality. Here are some things typically different for different compilers
- how to define interrupts
- specify certain class/type of memory to use
- built-in functions or device-support functions
- other device-dependent aspects
- some areas are stronger/weaker for optimization
To elaborate on the last item, this compiles much cleaner if I don't use indexed arrays. Using char pointers rules in GCC. Although CW seems better in that case, it seems worse in other cases or compared to yet another compiler. Too often people are limited by their tool, and spend too much time changing or learning tools instead of improving applications.
The complaint about the compilers requiring slightly different syntax is a fair one - but I thought that all of the ANSI C compilers should use exactly the same syntax. I'm not sure if the code I posted is ANSI C or not, but I thought it was. Where did you get the GCC compiler? I was not aware of it.
Syntax is a big one, no matter how ANSI it is, because embedded devices are not the system C had in mind. Is there a standard for how to specify which interrupt vector, or which Flash bank to use? If so, this demonstrates that C compilers don't always use it. GCC claims certain standard compliance, but I admit this one has had trouble satisfying some common expectations. It needs more help developing.
The extra pushes you wonder about are because GCC was made to use significantly more hardware registers than HC11/12 has. That's why people don't even
want to port it to HC08. It defined "softreg" variables to solve it. Then since ISR could need the temporary softregs, it decided to push/pop them and that created the mess. I've apparently convinced the author to use local stack space instead of other softregs _.d1 to _.d32 (16-bits each). These were considered optional but did not compile if it didn't know any other way. One reason that certain of these are still pushed even if not used in any function is likely for consistency. Some applications require to know how many bytes were pushed on the stack for the ISR call. I would like to eliminate
all these softregs, but it would of course make even more YAVs (yet another variation).
*See
docs*YAV: Yet Another Variation
But all in all, I like this C compiler once I learn to avoid these hurdles because it's just like you said. C code has to be "well written" to be practical. Hope you learned alot you didn't know about "C" compilers, and there's more yet :smileywink:
Here is the
link for GCCMessage Edited by imajeff on 2006-06-0908:37 AM
* added "device-support" item to list
Message Edited by imajeff on 2006-06-09 08:42 AM
Message Edited by imajeff on 2006-06-09 08:44 AM