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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
03/23/10 17:34
Read: times


 
#174439 - Create a Compiler header
Responding to: ???'s previous message
Per Westermark said:

Another thing here is that compiler vendor X may decide to change the memory layout of their data structures between versions of the compiler, in which case the source code will recognize the compiler but fail to notice that the manually corrected code isn't correct anymore.


Add the version

Per Westermark said:

Another thing - exactly how readable is code with a lot of #ifdef sprinkled?


quite readable by using top-down programming methodology instead of mixing in bottom-up. Create a header file for example

#ifdef KEIL               // KEIL compiler

#  define Reentrant(x)    x reentrant
#  define Sfr(x,y)        sfr x = y
#  define Sfr16(x,y)      sfr16 x = y
#  define Sbit(x,y,z)     sbit x = y ^ z
#  define Interrupt(x,y)  x interrupt y
#  define At(x)           _at_ x

#  ifdef __C51__          // C51 Compiler
#     define far  xdata   // far is for C251 only
#  endif
#endif                    // End of KEIL

#ifdef RAISONANCE         // RAISONANCE compiler

#  define Reentrant(x)    x reentrant
#  define Sfr(x,y)        sfr x = y
#  define Sbit(x,y,z)     sbit x = y ^ z
#  define Interrupt(x,y)  x interrupt y
#  define At(x)           _at_ x

#  ifdef __C51__          // C51 Compiler
#     define far  xdata   // far is for 251 only
#  endif
#endif                    // End of RAISONANCE

 


Per Westermark said:

And how much time do you save by testing your #ifdef section and documenting it, compared to just writing portable code?


Takes quite a bit of time in the beginning, but using top-down methodology, one can keep using compiler.h and put that in their toolbox. Thereby, reducing the overall time in the long run.

Per Westermark said:

If a new programmer gets involved in the project - do you think the new programmer will be more comfortable trying to read through your documentation about special cases, or instead seeing traditional portable code?


Even better that a new programmer learn top down programming instead of picking up bad habits to begin with.

List of 23 messages in thread
TopicAuthorDate
Unions and position of bytes            01/01/70 00:00      
   Syntax and strategy problem.            01/01/70 00:00      
      wow that was quick and excellent thanks            01/01/70 00:00      
      Works a treat            01/01/70 00:00      
   Note that this is heavily compiler-reliant            01/01/70 00:00      
      Code for transparency            01/01/70 00:00      
         Agreed - after bitter experience            01/01/70 00:00      
            Compiler Specific            01/01/70 00:00      
               How many compler brands/versions to test for?            01/01/70 00:00      
                  Create a Compiler header            01/01/70 00:00      
                     Didn't we talk about unions - your examples doesn't...            01/01/70 00:00      
                        Someone already wrote up a good way....            01/01/70 00:00      
                           Incomplete byte order. But pad is still dangerous            01/01/70 00:00      
                              why bother?            01/01/70 00:00      
                                 how would you know?            01/01/70 00:00      
                                    Exactly my point... you don't            01/01/70 00:00      
                                       Never give up on portability - just decide the amount            01/01/70 00:00      
               Yes, but            01/01/70 00:00      
               why bother?            01/01/70 00:00      
      unions and portability            01/01/70 00:00      
         OT: use TR0 = 0; TMR0 -= offset; TR0 = 1;            01/01/70 00:00      
         you're not?            01/01/70 00:00      
            It was just a warning that union type casts are dangerous            01/01/70 00:00      

Back to Subject List