Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
01/22/08 15:06
Read: times


 
#149848 - how portable?
Responding to: ???'s previous message
below I use the expression
'pseudo-portable' in the meaning "portable with little effort" as opposed to
'portable': potable with no effort or
"not portable": code must be totally analyzed if ported.

When thing's are interconnected, you need a common "protocol" - and having to manually re-write it at each end is folly.
totally agree. Now, if we look at well wsritten '51 code how many "split shorts" will you find? I bet very few. Thus I a) avoid "split shorts" and "split longs" as much as I can and b) only do those in two 'standard' unions "splitAshort" and "splitAlong". Thus without messing up the code with tons of #ifdefs" I have two, and only two, things to replace i.e. all uses of the aforementioned unions.
to write e.g.
#if KEIL
U16x = ((U16) U8a << 8) + (U16) U8b;
#else if ACME
U16x = ((U16) U8b << 8) + (U16) U8a;
#else
new unknown compiler
#endif
all over creation is quite messy and error prone.

in my case I looks like this
union SplitAshort SASx;

U16x = (U16)SASx.c[0] + (U16)SASx.c[1];
which, of course, will have to be changed if you decide to use the Acme compiler; however a global search on 'SAS' will give you every place to change.

Now if you refer to memory spaces and such, that, of course, is totally pseudo-portable when definitions are used (as I do).

If you design it to be portable, the overhead isn't that great and is certainly worth it.
It is certainly a lot less effort than trying to make something portable after the event, or trying to port something that could easily have been made portable in the first place.

I guess that what the discussion is (and am sorry I failed in making that clear) is NOT portable or not, but "how portable". I would hold my code for being portable, many would not, simply because it will take 10 minutes longer than just changing a #define to use it on another platform. However, no 'analysis' of the code would be required.

"fix the compile errors" by observing and changing every U16 to UI while checking if the endianness matter (sounds cumbersome, but is not - I have done it)
I was not referring to ALL U16s (and, again am sorry I failed in making that clear) I referred to the above mentioned "splitAshort" and "splitAlong"

I hold the portability of code for small embedded to be a generally overemphasized issue; hovever I do, of course, write my code pseudo-portatble.

Erik

List of 19 messages in thread
TopicAuthorDate
SDCC, copying integer in ASM            01/01/70 00:00      
   Shift-and-mask, or union            01/01/70 00:00      
      I used asm tag and the rr command but....            01/01/70 00:00      
         Your question            01/01/70 00:00      
            Portable unions            01/01/70 00:00      
               Less non-portable?            01/01/70 00:00      
                  Less non-portable            01/01/70 00:00      
                     portable, schmortable            01/01/70 00:00      
                        Disagree!            01/01/70 00:00      
                           how portable?            01/01/70 00:00      
                              emphasis            01/01/70 00:00      
                        Real world portable            01/01/70 00:00      
      using - does not give the same result            01/01/70 00:00      
         try this            01/01/70 00:00      
         You are exceeeding 2 byte signed integer limits            01/01/70 00:00      
            Fighting the tools            01/01/70 00:00      
   Thanks all.            01/01/70 00:00      
      Dangerous            01/01/70 00:00      
         Very important warning!            01/01/70 00:00      

Back to Subject List