Continue to Site

Efficient C programming

Status
Not open for further replies.

banh

Advanced Member level 1
Advanced Member level 1
Joined
Dec 16, 2004
Messages
458
Helped
17
Reputation
34
Reaction score
5
Trophy points
1,298
Activity points
3,935
I wish to find ebook on this matter.
How to optimize your code and how to program in efficient ways (in terms of space, speed for example) ?


one found-out link is from embedded.com:
https://www.embedded.com/98/9811/9811fe3.htm
(Efficient C Code for Eight-Bit MCUs )
 

look for this book:

The ANSI C Programming Language - Ritchie & Kernighan 2n ed


mayyan
 

unfortunately my school library does not have it :(
 

The most efficient embedded code is actually asm code. But if you are really unwilling to go through the hassle of assembly, at least try to understand it, and add in snippets of inline asm in your C code. The only other advice I can give is always start from the basics. For efficient code, throw out all provided libraries and write everything from the start. Libraries are meant for modularisation most of the time and don't stand hand in hand to efficiency.
 

agree :).
but i prefer exploiting from the C level as much as possible...btw it's still more understandable than asm..
 

the ANSI C book is available in pdf format.. if u wouldnt know it...


go here: direct pdf link

h//p://www.mmg.vmei.acad.bg/e-books/K-R-C-Programming.pdf

// => tt

/Am
 

thanks :) is it the book by C original author Ritchie?
 

banh said:
thanks :) is it the book by C original author Ritchie?

yes... there are more than this link available in EDAboard.. use the search option tofigure them out! good luck!

/Am
 

Hi

I order to program efficient C code you must:

1st. know very good the C language - you can write the same program in C in 30 differnt ways!!!!

You must know very well the controoller hardware structure - some controller like

MSP430 & AVR are desigend to be C efficient.

Most of the knowldge came from experience and some from the books.

for instance :

If your controller is 16 bit type use INT variable to transfer data between function and not CHAR's

Best regards

Bobi
 

I don't know much but I think when you use assembler you have to know everything about that microcontroller <---different ---> use C compiler .Am I right?
My bro buy for me the ke il compiler and now I'm beginning learn C and Keil
 

tocal09 said:
I don't know much but I think when you use assembler you have to know everything about that microcontroller <---different ---> use C compiler .Am I right?
My bro buy for me the ke il compiler and now I'm beginning learn C and ke*il

at first, using C might be tempting you from digging into the microcontroller hardware...
but gradually... you'll have to know soon.
 

Some Tips on C programming for embedded sytems
1) Use registers for local variables. Your compiler will help in this
2) Pass by address rather than by value
3) Remember Modularity and efficient code does not go together.
4) Reusing of local variables can save you significant stack size and improve speed.
Hope this helps,
madhukar
 

Pass by address rather than by value

only when to-be-passed data is big (usually a struct)..

for e.g. u need to pass only 8 bits, should not pass by value rite? as address may be in 16-bit format.

Reusing of local variables can save you significant stack size and improve speed.

can you clarify on this?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top