Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
C - why is slow to write and debug) but fast to run?

I often say on my courses that you can write code in a morning in Perl, Python or Ruby that would tae a week in C. How come, and why would anyone use C these days?

Firstly, C is the underlying language on which others are built. We need it there in the background, even if we don't (ourselves) code in it. It's used for the operating system, for the other language compilers ... very much like a building needs foundations, but even the keenest DIY experts will rarely mess with foundations.

Secondly, C is very fast when it (eventually!) runs. The language trusts the coder to get things right, rather than imposing checks and balances at run time. And if your code needs to run very fast, and be compact, you'll never be able to do better than optimised "C" if you're using an alternative language that's written in C itself.

We teach C anc C++. For the right applications, they remain required languages and we're a niche provider; it may be that you need to do huge numbers of calculations, to maintain existing code, to work with embedded systems, device drivers, etc ... and I am happy to teach you, even if you feel you're doing an awful lot of work compared to other languages.

A new example of what you need to check for / what can go wrong in C has been uploaded [here] on our web site ... including a plea to readers to note that the code is a series of examples of what not to do!

So - what are these thsings that I've done in my example?

• I've used a short ints to hold numbers which when added up exceed the range of a short int - resulting in the calculated value wrapping round and being incorrect

• I've made use of an uninitialised variable - resulting in an undefined value being used which is likely to vary each time I run my program

• I've accessed an array beyond its declared scope - resulting in goodness only knows what data being changed and presented; I took this example even 'wider' off the array when I first wrote it, and my program "hung" - probably in an infinite loop as I suspect I was resetting the variable that contained my loop counter every time around the loop

• I've accessed memory through an undefined (uninitialised pointer) resulting in me choosing to work at a random position. In my sample run, I just got a silly values out, but I could have got all sorts of bus or segmentation errors.

• I've printed out a floating point number using an integer conversion - and the result is based on the bit pattern of the float and not simply the whole number part of the float. at least my compiler gave me a warning about this one!

• I've tried to alter a character string that can't be altered. No compile time error, but a bus error when I ran the code.

In an example that's set up this way, it's easy enough for me to show you the problems and explain them - but it can be quite a different thing for a newcomer to C to avoid making any of these errors - or spot them if they have been made and need correcting - in a practical programming environent. So C coding calls for time, testing, discipline on the part of the programmer, and the splitting of code into a series of managabale functions rather than running as larger blocks.

For details of our C and C++ courses, see [here].
(written 2015-11-01)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
C205 - C and C based languages - Arrays
  [1614] When an array is not an array - (2008-04-17)
  [2002] New C Examples - pointers, realloc, structs and more - (2009-01-20)
  [2840] Just pass a pointer - do not duplicate the data - (2010-06-30)
  [3118] Arrays of arrays - or 2D arrays. How to program tables. - (2011-01-02)
  [3121] New year, new C Course - (2011-01-05)
  [3144] Setting up arrays in C - fixed size at compile time, or dynamic - (2011-01-24)
  [3245] Collections in C and C++ - arrays, vectors and heap memory blocks - (2011-04-12)
  [4338] Passing arrays into functions in C - (2014-12-02)

C201 - C and C based languages - C Language Fundamentals
  [888] Turning C from source to a running program - (2006-10-06)
  [1671] Compiling C programs with gcc - an overview - (2008-06-10)
  [2005] Variables and pointers and references - C and C++ - (2009-01-23)
  [2576] What does const mean? C and C++ - (2010-01-15)
  [2842] Staring a C course with Hello World - why? - (2010-06-30)
  [3120] Learning to write good programs in C and C++ - separating out repeated code - (2011-01-04)
  [3234] Your program - you just provide the filling in the sandwich - (2011-04-08)
  [3278] Do I need to initialise variables - programming in C, C++, Perl, PHP, Python, Ruby or Java. - (2011-05-05)
  [3591] Integer types, and integer overflows, in C - (2012-01-25)
  [3917] BODMAS - the order a computer evaluates arithmetic expressions - (2012-11-09)
  [4324] Learning to program - variables and constants - (2014-11-22)
  [4555] Preprocessor directives in C and C++ - what they mean - (2015-10-27)

C230 - C and C based languages - Revision of C
  [4466] Moving from C to C++ - Structured to Object Oriented - a lesson for engineers - (2015-03-28)


Back to
Allocation of memory for objects in C++ - Stack v Heap
Previous and next
or
Horse's mouth home
Forward to
Japanese and Malaysian food in Melksham
Some other Articles
A warm welcome awaits you at Well House Manor, Melksham
Lua - changes to how integers and floats are handled - 5.2 to 5.3
Moderation - and the tendency to over-moderate
Japanese and Malaysian food in Melksham
C - why is slow to write and debug) but fast to run?
Allocation of memory for objects in C++ - Stack v Heap
Perl, PHP, Python, Lua, Tcl, C++, Ruby - final public courses for 2015
Formatting and outputting your own classes in C++
Left shift operator on an output stream object - C++
Hello World in C++ - a first program, with the process explained
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2021: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/4566_C-w ... -run-.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb