SDCC seems to be irritated by a NOOP cast (unsigned int
to unsigned int).
------8<-----------------------------------------------
/* Macro to swap signed integers, needing a cast */
#define SWAP1(x) (((unsigned int)x>>8) | ((unsigned
int)x<<8))
/* Macro to swap unsigned integers */
#define SWAP2(x) ((x>>8) | (x<<8))
unsigned int u; /* signed int is not better;) */
unsigned int f(void) {
return SWAP1(u); /* not recognized as swap, (16 byte) */
}
unsigned int g(void) {
return SWAP2(u); /* fine, (7 byte) */
}
Logged In: YES
user_id=203539
I've commited a fix to remove the NOOP cast (rev. 4124) in
the unsigned case.
This doesn't improve the code for the signed swap. I'm still
looking for a clean, elegant solution. I'd like to improve
the macro itself, but I still don't know how it can be done.
Another approach is to expand optimizeSWAP() in SDCCast.c,
but this is somewhat messy.
The problem is that the task itself is dubios. Why do you
want to swap a <signed> variable? Isn't it acceptable that a
dubios source is punished by lengthy code?
If you're already happy with the current code, please close
the RFE.
Logged In: YES
user_id=589052
thanks for the quick fix:)
The signed swap macro is convenient if the
'51 is connected to a big-endian outside world.
I'm not currently having this problem, just
noticed it wouldn't work as I hoped:)
I admit it's probably a niche task, you might
close it if you wish.
Logged In: YES
user_id=203539
> The signed swap macro is convenient if the
> '51 is connected to a big-endian outside world.
Ok, good point. I leave it open.