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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
12/04/07 19:28
Read: times


 
#147863 - Small and easy things that may make Your day
Responding to: ???'s previous message
I try to list here some of the things that I always do when I start a new project. For most of You this stuff is Your daily bread but then again I have seen threads that start: "Should I put my strings in the stack or in the memory?" ......

  • I create an #include file which is private to the project and where I declare all the bits and ports etc. I'm going to use in the project. Most of this is just including vendor spesific header files but definitions like CPU frequency or port usage are here. Also, because I usually split the project into small modules I have a bunch of extern declarations here.

  • I never leave data or function without the static or extern declaration. Extern declarations are in the private header file and the static ones are in each source code.

  • There is a common <portable.h> file which is included. This file contains declarations that might or might not be supplied by the compiler. Declarations like uint8_t, int8_t, bool_t, schwartzenegger_t and so on. Then in the actual code I never use any other data types than those declared in that file. Structures, arrays and other derived datatypes are ofcourse an exception but still those use the declared datatypes. C compilers tend to have different default data types and this is a no-no with embedded coding. You have to know exactly what You are dealing with.

  • When using division or multiplication I am extra careful with data types. A single innocent looking division can easily consume additional half a kilobyte if You forget to use correct datatypes. This is especially true for constants which take the default data types if not typecasted properly. Remember, there is a separate piece of code for each combination of division and multiplication versus datatypes that get linked with the final binary only when used.

  • I ONLY use #ifndef ... #endif for inhibiting the include file to be loaded twice. I hate conditional C.

  • If I have created libraries, these never contain any MCU spesific stuff. All the knitting is done on separate subroutines which are NOT present in the library itself. This means that I have to compile and link those routines separately. Like Erik, I have skeletons which I modify to apply to the project in question. The skeletons have enough comments so that it is easy to code them even if You are a tad demented like me.

  • Warning == Error.


  • Actually everything else is just pure, workhorse type coding. Nothing fancy with that one.




    List of 20 messages in thread
    TopicAuthorDate
    How to write portable code            01/01/70 00:00      
       C is a language - not a compiler            01/01/70 00:00      
          PL/M            01/01/70 00:00      
             Have you considered PLM2C?            01/01/70 00:00      
       A good point - often missed            01/01/70 00:00      
       So what's the downside?            01/01/70 00:00      
          Complex code - Libraries            01/01/70 00:00      
             COTS libraries versus inhouse libraries            01/01/70 00:00      
                Hence portability is not such a big issue!            01/01/70 00:00      
          There are downsides            01/01/70 00:00      
             Portability vs. Readability/Maintainability.            01/01/70 00:00      
       who gives a hoot about portability            01/01/70 00:00      
          Portable by BIOS            01/01/70 00:00      
       I give a hoot about portability            01/01/70 00:00      
          I am definitely not arguing against "code reuse"            01/01/70 00:00      
             HAL            01/01/70 00:00      
       Small and easy things that may make Your day            01/01/70 00:00      
       The developer is probably the biggest factor            01/01/70 00:00      
          I may take issue with this one...            01/01/70 00:00      
       general re 'portable code'            01/01/70 00:00      

    Back to Subject List