"John R. Strohm" wrote in news:bpdccm$ snipped-for-privacy@library2.airnews.net:
First, you can't have a variable names 'switch' since this is a keyword. Second, I was asking about static not not having program duration for a function, not a variable.
Do you mean C99? Harbison and Steele, "C - A Reference Manual" does a good job of covering (and comparing) all versions of the standard, and pre-standard C. I would not recommend it to a beginner, but it's a good reference book, especially as compilers are becoming more C99 compliant.
--
Al Balmer
Balmer Consulting
removebalmerconsultingthis@att.net
We were talking about variables, not functions. But since you mention it: code banking / overlaying works by essentially the same "as if" rule. From the abstract point of view of the compiled code, it looks as if all functions were available at all times, when in fact they're not.
But a compiler like Keil's C51, which already does static call tree analysis anyway, could reasonably easily discover that function foo() was only ever called a couple of times early on, and then never again. Now, if there's a static-duration variable "bar" that's used only by foo(), and another static-duration variable "bletch" that is not used at all before the final call of foo() has terminated, then "bar" and "bletch" _can_ be put in the same memory position, because there's no way the code could know about this.
Whether or not a compiler actually attempts to exploit this possibility is mainly a question of motivation. It's absolutely allowed by the language definition, but may not be applicable frequently enough in real-world code to be worth the bother. Clever programmers may even find this optimization on their own, if pressed for space.
The "as if" rule is simple: as long as the program behaves the same way (in all aspects that the standard defines) _as if_ the optimization hadn't taken place, the optimization is allowed.
The architecture does not influence this much, if at all.
--
Hans-Bernhard Broeker (broeker@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.
If someone wants to learn programming, I suggest they first learn a language other than C. Learning some assembler as well doesn't hurt either.
For the experienced programmer who wants to learn C: K&R2.
For the experienced C programmer who want to become better: PvdL "Expert C Programming: Seep C Secrets" (There may be some controversy about this one's style and UN*X-centeredness, but it contains a lot of good info on topics most books gloss over, like the difference between arrays and pointers, and how to read complex declarations).
For someone who wants to actually write a C compiler: H&S5. And the standard, of course. I bought H&S3 when it was new when I wrote my first C language parser...
Learning some assembler is highly recommended. I think I also agree that C is not the best first language for a beginner, though it's probably not the worst, either. Personally, I learned Fortran, assembler, PL/I, and C, in that order. I can't say I'd recommend Fortran and PL/I as first languages, either ;-)
--
Al Balmer
Balmer Consulting
removebalmerconsultingthis@att.net
C is definitely not a good first language. Though not amenable to embedded work, I (and many others) think that that Python makes an excellent first language for somebody wanting to learn programming.
formatting link
--
Grant Edwards grante Yow! Where's th' DAFFY
at DUCK EXHIBIT??
visi.com
Most adheres to C90+ Some now almost C99. Certainly all the compilers are somewhere between C95 and C99. Many of the things in K&R are not permitted in many coding standards etc.
There are also many better books for learning C especially fro some one coming from an assembly background to embedded c.
I have seen the effect of a K&R taught programmer coming to grips with an embedded project... wanted to use sdterr and printf to hard disk for debugging on an 8-bit smart card....
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/\ /\/\/ snipped-for-privacy@phaedsys.org
However it does not work with many embedded compilers. Some of the constructs are not permitted in most modern coding guides. It also misses things like const etc
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/\ /\/\/ snipped-for-privacy@phaedsys.org
Nothing could be further from the truth. K&R 2nd ed was published before the US C89 or the ISO C90
Most C books cover the C90+TC's and A1 (ie C93 or C95) which is what most compilers use as a base. Compilers are moving (slowly) towards C99 as are most books. This leaves K&R very out of date.
It is an interesting book to have once you have learnt C in much the same way I would like to drive a model T Ford but I would not recommend learning to drive on the freeway in one.
Strange since I review books on that and we dissagree :-)
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/\ /\/\/ snipped-for-privacy@phaedsys.org
Do note there are several versions still in print. I have the forth edition which is dated 95 and does cover the standard as used in most compilers. The later edition covers C99
Many regard this as the successor to K&R
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/\ /\/\/ snipped-for-privacy@phaedsys.org
K&R is probably not a good idea then. I would look for a book on C that uses the Z8 as a target. This will probably be based on the compiler you will end up using. See what the compiler vendors for the z8 recommend.
Whilst it will not be portable C neither is any one else's C. Most "standard" C books use M$ Windows as a platform and the C you will use on that is going to be different in to the C on an embedded target.
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/\ /\/\/ snipped-for-privacy@phaedsys.org
sorry, i seldom see standard c programs that do any real work. most are full of platform specific types, inline compiler, link, or source control commands, inline assembler, etc.
also, many c compilers have an option to allow k&r syntax.
in a perfect world, all c code would conform to the latest ISO.
actually, in a perfect world we probably would not be writing programs in c. :)
however, you do make a good point that the k&r book is probably not a good transition text from assembler languages to c. the authors of the book disliked assembler and actually developed c so that they wouldn't have to use their assemblers.
Sorry I can't help with the original question, I have a question of my own.
You may laugh at the next bit but....
In 1982 in had a BBC micro (people in the UK will know what I mean).
I played with it for ages and could write in BBC basic pretty much what I wanted, if I needed more speed I just dropped in to assembler BBC basic would let you do that.
I could talk down the serial bus, centronics etc. bus with absolute ease.
Then I thought I'd try some other languages such as Forth and C.
C amazed me. I looked 20 years out of date 20 years ago. The syntax looks to the untrained eye like somebody's tried to press as many shifted character keys as possible i.e. $%& etc. And it was so slow in comparison to what I been used to. I seems to me you have to include so much junk to do a simple job like talk to the serial port your programme ended up being bigger than the BBC Basic interpreter just to do 1 simple thing.
Surly by now there must be something better because its look to me like there have been no advances in programming since 1982. If anything it looks worse. Is this why so much modern software is in all honesty, junk, is it written in C.
"Better" is in the eyes of the beholder. Some people want to write a one line program to do everything, other people want control over the intermediate stages. It's a single command to delete all the files on your hard disk, but does that mean the command line language is "better" than assembler?
Do you want a language where you can just drag a text GUI window onto a titlebar window in order to create a functioning word processor, do you want a language where you can fit your device driver into 4K of RAM, or do you want a language where file operations can be abstracted into database operations?
ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here.
All logos and trade names are the property of their respective owners.