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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
07/27/06 10:31
Read: times


 
#121153 - That's your trouble, then!
Responding to: ???'s previous message
Jan Waclawek said:
- in C, except gurus, nobody knows what does "int" mean (even "short" or "long" won't make it any better)

This perfectly illustrates the point that it's not the language that matters ('C', assembler, whatever), but the skill and experience of the programmer.

Of course, anyone experienced in language-1 but inexperienced in language-2 will do things better in language-1 than language-2 - whether that's porting, writing efficient code, or whatever.

This is where the fallacy of "Assembler gives tighter code" lies; I've said it many times before - it's not Assembler itself that gives tighter tighter, it requires a skilled & experienced assemlber programmer to do it.

The same applies to writing "portable" code in 'C' - as Erik so often says, if you just assume that your code must be inherently portable simple by virtue of writing it in 'C' ("C is C"), then you are seriously mistaken!


This is what I meant by doing your 'C' code carefully!

The 'C' standard specifically states that the sizes of the data types are implementation-defined (it requires a minimum of 16 bits for int; but nothing else)

The first step to portable 'C' is to never use the standard types - int, long, etc - always define your own of known signednes and size; eg,
typedef unsigned char     U8;
typedef   signed char     S8;

typedef unsigned short   U16;
(or use the C99 well-defined types, if your compiler supports them)

Similarly, all other implementation-specifics need to be isolated in #defines or similar.

- gcc made an unexpected retyping (expansion) and sign extension when shifting

I think you'll find that this is all standard 'C' behaviour, or documented implementation-specific behaviour.

It seems to me that that AVR-GCC places more importance on standards-compliance than on efficient code generation...


List of 26 messages in thread
TopicAuthorDate
How long we see 8051            01/01/70 00:00      
   unofficial history of 8051            01/01/70 00:00      
      History, or prediction?            01/01/70 00:00      
         It seems to gain, not lose            01/01/70 00:00      
   Does it matter?            01/01/70 00:00      
      Double negative?            01/01/70 00:00      
      to C or not to C            01/01/70 00:00      
         Defintely 'C'!            01/01/70 00:00      
            yeah, let's flame!            01/01/70 00:00      
          Defintely 'C'!            01/01/70 00:00      
            arguments            01/01/70 00:00      
               An example for 8051/AVR            01/01/70 00:00      
                  contra-example for 8051/AVR            01/01/70 00:00      
                  A slight mistake            01/01/70 00:00      
                     stdint.h            01/01/70 00:00      
               That's your trouble, then!            01/01/70 00:00      
                  Compiler independant            01/01/70 00:00      
                  C is not better            01/01/70 00:00      
                  bringing 2 togethert            01/01/70 00:00      
                  Opening pandora's box            01/01/70 00:00      
               Learning C            01/01/70 00:00      
                  for a beginner ...            01/01/70 00:00      
            are You sure?            01/01/70 00:00      
            Portability and scars            01/01/70 00:00      
   I'm an ASM Guru but            01/01/70 00:00      
      why discuss the rare exception tha same apply            01/01/70 00:00      

Back to Subject List