'''[http://www.open-std.org/JTC1/SC22/WG14/www/standards%|%C]''' is a [programming language], most notable as the implementation language of [Tcl] ;) ** Critique ** [1% the code]: ** Documentation ** [http://busybox.net/~landley/c99-draft.html%|%C99 Draft (N869)]: at busybox.net [http://web.archive.org/web/20050207010641/dev.unicals.com/papers/c99-draft.html%|%C99 draft specification]: big HTML file [The C Programming Language Kernighan and Ritchie%|%The C Programming Language], by [http://cm.bell-labs.com/cm/cs/cbook/index.html%|%The C Programming Language, Second Edition], by Brian W. Kernighan and Dennis Ritchie: [http://cm.bell-labs.com/cm/cs/who/dmr/chist.html%|%The Development of the C Language*], Dennis M. Ritchie: [http://c-faq.com/%|%C FAQ]: [http://www.lysator.liu.se/c/%|%Programming in C]: a list of various C papers and resources ** Description ** The ANSI committee as well as the ISO committee have approved a standard reference for C. Support for C is traditionally provided by a compiler. Some efforst at a C interpreter also exist. Most Unix systems provide vendor-supported compilers. They are often unbundled products these days. ** Dialects ** [http://cyclone.thelanguage.org/%|%Cyclone]: a safe dialect of [C] ** Free Compilers ** [gcc] , by the [FSF]: a quite popular C compiler found on many platforms and operating systems. Apple [XCode] provides a gcc distribution for [Mac OS X] . [clang]: C language family frontend for [LLVM] [http://clang.llvm.org/] [Cygwin]: C compiler (free; a version of [gcc]; for some strange reason it cannot be used to compile the [Tcl] source code out-of-the-box - but Cygwin comes with its own version of Tcl at least), [Mingw]: C compiler [http://www.mingw.org/] (free; another version of [gcc] for Windows with goals slightly different from [Cygwin]), [http://www.openwatcom.org/%|%OpenWatcom C/C++ compiler]: Free . [Microsoft Windows] , [OS/2] , [MS-DOS%|%DOS] , and [Linux] . [tcc]: the "Tiny C Compiler" . Free . [http://www.t3x.org/subc/index.html%|%The SubC Compiler], by Nils M Holm: Free . A fast and simple public domain compiler for a clean subset of the C programming language. It can compile itself and passes gcc -Wall -pedantic. Companion to [http://www.t3x.org/reload/index.html%|%Practical Compiler Construction: A Non-nonsense Tour Through a C Compiler]. ** Proprietary Compilers ** [Microsoft] Visual C++: Commercial . Now only avaialable as a component of Visual Studio . [C++Builder]: Commercial . An older command-line version is still available as a free download freescale [http://www.freescale.com/webapp/sps/site/homepage.jsp?code=CW_HOME%|%CodeWarrior]: Commercial . Previously by Metrowerks . Versions for [Microsoft Windows%|%Windows] and [MacOS Classic] and [MacOS X] previously existed . [http://www.digitalmars.com/%|%Digital Mars C and C++]: Commercial . No charge . Was once Zortech C and later became Symantec C [http://www-03.ibm.com/software/products/en/ccompfami%|%IBM XL C and C++]: Commercial . For [AIX] , IBM i , Blue Gene , Linux , z/VM , Z/OS [http://www.cs.virginia.edu/%7Elcc-win32/%|%LCC-Win32]: Commercial . No charge for non-commercial use . [http://www.intel.com/software/products/compilers/%|%Intel C++ compiler]: Commercial: ** Historical ** [http://macintoshgarden.org/apps/macintosh-programmer%E2%80%99s-workshop%|%Macintosh Programmer's Workshop]: for [MacOS Classic]: Abandonware ** Interpreters ** [http://root.cern.ch/root/Cint.html%|%CInt]: [RFox]: a (free) interpreter, originally from Masaharu Goto, and apparently currently maintained by the CERN Root team which uses CInt as its scripting language. I do not know if [Tcl] can be interpreted under this interpreter [http://www.softintegration.com/%|%Ch]: a C/[C++] interpreter that runs cross-platform on a large number of operating systems and hardware. It provides not only standard language features, but also support for 2 and 3 dimensional plotting, shell programming, and numerical programming. It supports 1990 ISO C standard as well as C99 features. In Jan, 2003, the product page for Ch Standard says that the product is free for use on Unix, Linux, and Mac OS X. [http://eic.sourceforge.net%|%EiC]: another C interpreter. ** Linkable Compilers ** Support for C can also take the form of a run-time compiler. [tcc] provides a libtcc library, which allows a running program to compile and link C code without touching disk. In milliseconds for a small chunk of code. (x86 only as of Jun 2003) [Odyce] ** C Annoyances ** [AMG]: One annoying thing about C is that, like [Fortran], it uses '''`=`''' as its assignment operator. This is very easy to confuse with the comparison operator '''`==`''', resulting in either of the following two coding errors: ======c x == 5; /* Nothing happens, except maybe a warning if -Wall is on. */ if (x = 6) {...} /* Unintended assignment and incorrect logic. */ ====== [Algol] uses '''`:=`''' as its assignment operator, and [C] is ancestrally derived from [Algol], so I was always mystified about why [C] reverted to [Fortran]'s assignment syntax. But I just now figured it out, I think. A '''`:=`''' assignment operator looks almost identical to C's '''`!=`''' inequality operator, so using '''`:=`''' instead of '''`=`''' for assignment simply trades one potential coding error for another. To fix ''that'' problem, '''`!=`''' would have to be replaced with, say, '''`/=`''' (borrowed from [Ada]), but that (1) collides with the compound division and assignment operator '''`/=`''' and (2) breaks symmetry with the logical negation operator '''`!`'''. Or instead use '''`\=`''', but that will behave unexpectedly when placed inside double quotes. Or use '''`<>`''' and be like [BASIC] and [SQL]. Shrug! [PL]: the change from `:=` to `=` was made during the transition from BCPL to B (and simply kept when going from B to C), and IIRC the reason was that Ken Thompson felt that an operator that was going to be used as often as assignment was should be as short as possible. The reasons you mention may of course also have affected his decision, but there was never any secondary ambiguity with "divide-assign", which was written as `=/` in B. [bch]: One thing that I do in C (indeed, Perl too) is use typical [http://en.wikipedia.org/wiki/Value_(computer_science)%|%rvalues] on the left side when doing comparisons, which will fail compilation if the assignment operator is mistakenly used instead of the comparison operator. Eg: use `if(9==a){...}` instead of `if(a==9){...}`; in the case of mistakenly using assignment operator, this will fail `if(9=a){...}`, which is good; the programmer will be notified that his intent was mis-typed. If the rvalue is indeed on the right, though, one would have typed `if(a=9){...}`, which will compile, but is unlikely to represent the programmer's intent, and lead to hard-to-find bugs. Reading expressions written this way (w/ rvalues on left) may seem "backward" to some people, and the practice is affectionately dubbed [https://web.archive.org/web/20111119141013/http://stackoverflow.com/questions/2349378/new-programming-jargon-you-coined/2430307#2430307%|%Yoda Conditions], [http://en.wikipedia.org/wiki/Yoda] [AMG]: Cute. I've seen that style too. Unfortunately, it doesn't help when both sides of the comparison (or unintended assignment) are valid lvalues. Thankfully, gcc -Wall provides useful warnings: &| `x == y;` | warning: statement with no effect |& &| `if (x = y) {...}` | warning: suggest parentheses around assignment used as truth value |& To silence the latter warning on a case-by-case basis, type: `if ((x = y)) {...}`. In my opinion, the extra parentheses highlight the fact that this expression isn't Business As Usual, so the reader will look at it more carefully and is more likely to notice that it uses assignment instead of comparison. Of course, only silence this warning when the code really is doing what you intend, and please put a comment nearby to testify to this fact and explain why. Also, watch your warnings like a hawk, and don't release code that emits any warnings in your chosen build environment(s). (You can't control if some alien compiler puts out weird warnings because it used MS-Word to grammar-check your comments.) Sometimes I really do want my conditional expression to have the side effect of assigning into a variable. I need this when I want to save some intermediate value of a complex conditional for later processing. A simple example is calling a syscall (read()) that either returns a useful result (number of bytes read) or an error flag (-1, check errno for details). ======c if ((ret = read(fd, buf, max)) == -1) { perror("read"); } else { printf("read %d bytes\n", ret); } ====== This style is also available in Tcl: ====== proc getline {} {...} while {[set line [getline]] ne ""} { puts "got header line: $line" } puts "got blank line, the header is now done" ====== As you can see, Tcl makes it impossible to mix up assignment and comparison. ;^) ** Questions about C vs Tcl ** How does performance in Tcl compare to comperable programs in C? For instance, certainly there are types of programs which can likely be developed more quickly in Tcl than in C. Are there types of things that '''run''' faster in Tcl than C? If not, how much slower than C is Tcl? 10 times slower? 50 times slower? 100 times slower? ** Miscellaneous Thoughts ** [AMG]: I just thought of a cute alternate name for C: "lightspeed". You know, 'cuz physicists use the constant "c" to represent the speed of light. :^) I leave it up to you to figure out if this name has any deeper meaning. At least it would give C an excuse to have a [http://www.ocremix.org/remix/OCR01160/%|%snazzy, energetic theme song]. ** See Also ** [http://phaseit.net/claird/comp.lang.tcl/HowToC.html%|%Cameron Laird's personal notes on how to use C with Tcl]: [What 'embedding' means]: [How to embed Tcl in C applications]: [Adding Tcl/Tk to a C application]: [Extending Tcl]: [Writing Tcl-Based Applications in C]: [Building a custom tclsh]: [Tcl_Init]: [Init Scripts in the DLL]: [Tcl interpreter in C# Application]: [Adding Tk to an Existing Xt Program]: [Mixing Tcl/Tk and Xt Event Loops]: [Using Xlib With Tcl/Tk]: [3D Text for Tk in Unix]: [C compiled image processing on an interactive Bwise canvas]: [automatically generating socket based Tcl / C connection code, 1]: [automatically generating socket based Tcl / C connection code, 2, using bwise]: [Connecting Tcl/Tk with GNUstep Objective-C programs]: [Building Tcl with the free VC++ toolkit]: [How to invoke a C function from Tcl]: [Tcl and other languages]: [Critcl]: [C-header Parser]: [C code generators]: [C Language]: <> Language