[TUT] [SOFT] Guidelines for writing efficient C/C++ code

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What i could actually understand of that was helpful for a beginner c/c++ programmer like me. Thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for sharing that tutorial :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thnks!! xD

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

can u give me some good online free tutorials for learning programming microcontroller in c

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Try here.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It looks like the article is no longer available on eetimes.  I searched using the article ID.  I also tried searching by the title.  I got no joy in either case.

 

After googling the title, I found an article of the same title written in 2006.  Perhaps it's the same one indicated in the OP?  I thought I'd propose this as the new link for the article...

 

http://www.embedded.com/design/mcus-processors-and-socs/4006634/Guidelines-for-writing-efficient-C-C--code

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It is in fact the same article.

The 'restrict' keyword is a new one for me.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"Read a lot.  Write a lot."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Really, you never heard of "restrict"? It's fairly key for writing optimal code when, for example, you are processing image areas where it's kind of key to reassure the compiler that the pointer to the source and destination don't overlap (for example)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Really, you never heard of "restrict"?

Really.  Everyone has a blind-spot ;-)

It's fairly key for writing optimal code when, for example, you are processing image areas where it's kind of key to reassure the compiler that the pointer to the source and destination don't overlap (for example)

Image processing is far beyond my paygrade :-)

Seems "restrict" was added in C99.  Not anywhere to be found in K&R 2nd edition, nor in my oft-linked-to online reference The C Book.

 

I do find it in n1256 (and n1124).

 

Also:

https://en.wikipedia.org/wiki/Restrict

... and the links external therein:

http://www.cellperformance.com/mike_acton/2006/05/demystifying_the_restrict_keyw.html

http://www.oracle.com/technetwork/server-storage/solaris10/cc-restrict-139391.html

http://www.lysator.liu.se/c/restrict.html

 

I especially like:

THE RESTRICT CONTRACT

I, [insert your name], a PROFESSIONAL or AMATEUR [circle one] programmer recognize that there are limits to what a compiler can do. I certify that, to the best of my knowledge, there are no magic elves or monkeys in the compiler which through the forces of fairy dust can always make code faster. I understand that there are some problems for which there is not enough information to solve. I hereby declare that given the opportunity to provide the compiler with sufficient information, perhaps through some key word, I will gladly use said keyword and not bitch and moan about how "the compiler should be doing this for me."

 

In this case, I promise that the pointer declared along with the restrict qualifier is not aliased. I certify that writes through this pointer will not effect the values read through any other pointer available in the same context which is also declared as restricted.

 

* Your agreement to this contract is implied by use of the restrict keyword ;)

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"Read a lot.  Write a lot."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Sun. Jul 31, 2016 - 06:55 PM