![]() | This is an archive of past discussions about C (programming language). Do not edit the contents of this page. If you wish to start a new discussion or revive an old one, please do so on the current talk page. |
Archive 1 | Archive 2 | Archive 3 | Archive 4 | Archive 5 | Archive 6 | → | Archive 10 |
The page says the language B got its name from BCPL. But Wombat's encyclopedia says this is wrong. It says "B had nothing to do with BCPL. B was in fact a revision of an earlier language, bon, named after Ken Thompson's wife, Bonnie."
Jay 22:44 5 Jul 2003 (UTC)
Maybe it does but, at best, Wombat is a tertiary source, quoting a secondary source, Foldoc, and we have to ask ourselves "How do they know that ? What is their primary source for that information ?" Our source for the statement that "B is based on BCPL" is the primary source, User Reference for B, written by Ken Thompson, in which he states that:
This is a pretty unequivocal statement of B's ancestry from Ken Thompson himself. Having said that, I have no doubt that Ken reused code from his work on the bon compiler in writing the B compiler -- that's the nature of programming -- but according to Ken himself, the language design was based on BCPL, not bon, so it doesn't really matter what others say. -- Derek Ross | Talk 19:01, 2004 Jul 14 (UTC)
And indeed I did as you will see if you read my comments there. However it turns out that the document concerned is a description of bon. It has nothing to say about B. The best information that we have about the link between the names is that which comes from Dennis Ritchie, and he favours the B from BCPL explanation.
I would also like to point out that the Wombat article which you quote does not appear to be talking about name-origins of B, but rather about the development of the programming languages themselves, which is, of course, a different issue. It states that the B language is a revision not of BCPL, but of bon (which I have shown to be contradicted by Ken Thompson's statements) and that the origin of the name bon is Ken's wife's name (which may be true) but it does not say anything about the origin of the name, B.-- Derek Ross | Talk 22:07, 2004 Jul 14 (UTC)
Dennis Ritchie has made "The Programming Language B", available at [1]. It is in two sections, both of which I have read. Both mention the connection between B and BCPL. Neither mentions any connection between B and bon. In fact neither mentions bon at all, so I guess that we can discount what Wombat says. -- Derek Ross | Talk 20:56, 2004 Jul 16 (UTC)
I see that the spelling "behaviour" in place of "behavior" is used in the C programming language article. My copy of the C Standard uses ";behavior". Should this Wikiopedia article use spelling consistent with the C language Standard? Or, maybe there is more than one English language version of the C Standard? LarryW 01:57, 3 Aug 2003 (UTC)
There were no responses to my comment of 5th July suggesting B was a revision of bon and not BPCL as claimed. Hence I've made the change in the main page.
Jay 11:42, 10 Aug 2003 (UTC)
It would be nice to have a paragraph about other important libraries besides the standard C library.
Maybe glib, for instance. -- Taku 01:38, Nov 16, 2003 (UTC)
But according to the TRIPOS page, TRIPOS was was developed in 1978, five years after Unix was re-implemented in C. Which is right? -- Khym Chanur
I would like to split off anatomy of C section to its own aritcle and merge ANSI C and ANSI C standard library with this article. It is more relevant to discuss history or standards than syntax details in this article, I think. Any thought or objection is welcomed. -- Taku 01:38, Nov 16, 2003 (UTC)
" During the late '70s, C began to replace BASIC as the standard microcomputer language," : BASIC was never a "Standard" programming language in the '70s. It was a teaching language. Only with the rise of MS's Visual basic did it become a real-world language, and it's still very limited in its application (it's mostly useful for GUIs). orthogonal 04:01, 26 Nov 2003 (UTC)
I have removed the "standard" comment, since it is ambiguous. As well as the 1981 comment, since this text is not overly clear on this. Please direct such specific comments to my talkpage, to be sure I noticed them. Lirath Q. Pynnor
'C++ (thus avoiding the issue of whether the successor to "B" and "C" should be "D" or "P".)' Why would it be "P"? -- Ortonmc 04:15, 26 Nov 2003 (UTC)
Removed the image. To my understading of the ANSI C standard, void main(void); is not an acceptable prototype for main. Dysprosia 10:39, 27 Apr 2004 (UTC)
#include <stdio.h> int main(void) { printf("Hello World!"); return 0; }
A C program that prints "Hello world!"
One could probably use the new/nifty table image syntax to achieve a better result, but I'll muck around with trying that later. Dysprosia 12:33, 27 Apr 2004 (UTC)
I think the syntax highlighting is a mistake. While syntax highlighting is useful to programmers, anyone reading the article to learn about C won't know enough to benefit from the syntax highlighting, and worse, might mistakenly conclude that the syntax highlighting is essential to the code, or that one set of highlighting rules is standardized across the C Programming Language. (Furthermore, I think anyone learning the language should avoid highlighting until they fully understand the various entities being highlighted.) orthogonal 09:18, 15 May 2004 (UTC)
It should be noted, however, that for complex modern processors the machine code generated by C compilers is usually faster than hand-written assembly.
As Robert Dewar has pointed out, that is not a meaningful statement. The human can not approach the speed with which a computer compiles code. But if there is no time limit put on the human, eventually she will produce code that is optimal. In fact, a common first step in producing hand-tuned assembly is compiling the code with a good compiler, which makes it hard to be slower than the code generated by that compiler.
Any real comparision is going to involve a particular set of compilers, certain time limits and certain programmers (some of the published comparisons involve undergrads, which is certainly different from results using RMS and Mel), and is not going to be useful much beyond that. --Prosfilaes 01:40, 31 May 2004 (UTC)
Well, better is a tricky term. I think you have actually advanced an argument that a human, under the right circumstances, can make (a little bit of) a program run faster than the compiler can. This is surely true. One old joke was that you could always take out 10% (it just kept getting harder to do). On the other hand, there is a famous cautionary tale, I can not recall the source at the moment, about an "optimization" that did not get called for years. There is another school of thought which says that people can better spend their (valuable) time thinking about the choice of algorithm and overall design, and that the same effort spent in this way usually results in much larger payoffs in terms of speed.AJim 05:56, 31 May 2004 (UTC)
I think they meant faster as in faster speed in execution, not writing. Dysprosia 05:59, 31 May 2004 (UTC)
I also think they meant speed of execution. What I meant to say was that an hour invested in working on the overall design was likely to yield more of a speedup in execution than an hour invested in trying to write better machine code than the compiler. It is well known that given the same problem to solve, a group of programmers will sometimes produce programs with an enormous range of execution times. We are talking orders of magnitude here, not a few percent. Experienced programmers usually do much better than novices in terms of speed. What distinguishes the faster programs is not faster low-level optimizations, but faster algorithms. AJim 16:11, 1 Jun 2004 (UTC)
Think I disagree with this sentence:
I believe it could be
-- anonymous
Summary
On one hand, I want to say your proposed replacement is incorrect -- the original correctly describes 2 dimensional static arrays (and higher dimensions), while your replacement does not.
On the other hand, static arrays of more than 1 dimension are very rarely used in real programs. Nearly everyone builds higher-dimensional arrays out of pointers and (1D) arrays, as dynamic arrays, in exactly the way your proposed replacement describes. (A few people use "sparse arrays", which are dynamically built out of pointers and 1D arrays in a completely different way).
Details
The data structure that C creates when the source code says
double NewYork [10][10] = {0.0};
(a 2 dimensional static array) is simply a block of 100 double variables packed one right after the next; there is no array of pointers.
The handling of 2 dimensional static arrays in C is widely believed to be seriously flawed; see the C FAQ:
"Rather than worrying about all of this, one approach to using multidimensional arrays of various sizes is to make them all dynamic" -- http://www.eskimo.com/~scs/C-faq/q6.20.html
So when you want what mathematicians would call a 2D array of real numbers, most people end up using a (1D) array of pointers to (1D) arrays of double. We end up using an "array of pointers to arrays of pointers to arrays of double" for 3D arrays. That's all described in http://www.eskimo.com/~scs/C-faq/q6.16.html .
Because it's a bit of a hassle to do this for every array, many people wrap this all up in a matrix-manipulation library -- and unfortunately, there are tons of incompatible libraries for manipulating matrices in C.
--DavidCary 21:47, 10 Jul 2004 (UTC)
I'm the person who inserted the comment about multi-dimensional arrays being arrays of arrays. According to K&R section 5.7 Multi-Dimensional Arrays (I have the original here at work, so the updated version for ANSII C might have changed), when explaining the array day_tab, they state:
a two-dimensional array is really a one-dimensional array, each of whose elements is an array. Hence subscripts are written as
day_tab[i][j]
rather than
day_tab[i, j]
#include <stdio.h>
int main() { int a[2][2] = {{1,2},{3,4}}; int* b = &a[0][0]; int i; for(i=0; i<4; i++) printf("%d", b[i]); return 0; }
As for allocating multi-dimensional arrays, I had never heard of anyone doing it the way you describe, although it is no doubt possible. I'm not sure what you meant by metadata, however, since an array is simply a block of memory of the necessary size to store the data. In the case of a multi-dimensional array, each element would be a pointer to the second array.
BTW - I almost never use multi-dimensional arrays, and encourage my students to use arrays of structures instead. IMHO, they are a carry-over from when we didn't have data structures, and would use multi-dimensional arrays where the rows were for a given entity, and the columns were the fields of that entity.
BTW2 - I admit I'm an old fogey, but I really object to adding the comment lines for the hello, world application. Actually, I don't care for the return 0 being added for that matter. The beauty of that programming example was in its simplicity. The fact that the program is well explained immediately below doesn't (IMHO) the addition.
I think part of the confusion that arose from my original edits were because I made two unrelated changes that were perceived as related.
I commented on the nature of multi-dimensional arrays in C, and I added an example of how to create single-dimension dynamic arrays in C. I think somebody assumed I thought they were related, which is what started this whole thread. I almost never use multi-dimensional arrays, and never even considered trying dynamic multi-dimensional arrays. However, I have noticed that many of the C text books I have used for various classes claim that you can't have dynamic arrays in C, which of course is wrong. So, when I'm teaching C, I make it a point to mention those two things.
Sorry for any confusion. I'm still getting used to this sytem. Wrp103 18:27, 13 Jul 2004 (UTC)
Wrp103 16:17, 5 Aug 2004 (UTC)
I noticed that somebody deleted my example of a constructor, and replaced calls to malloc followed by clearing memory to calloc. The purpose of the constructor is to initialize the data structure to default/valid values; my example of zeroing the structure was for simplicity. BTW - NULL isn't always all zeros (I recall working on a mainframe where this messed up a lot of programs that used things like "if (ptr)", assuming NULL would return False.)
(Christopher Thompson added the next bit) The following makes no sense: In C, sizeof('a') == sizeof(int); In C, sizeof('a') == sizeof(char) (For the record this has been corrected now. Cyoung 04:12, 23 Sep 2004 (UTC))
Formally, C has only statically-allocated, fixed-size, one-dimensional arrays. (I ignore for the moment the variable-length arrays of C99.) But you can build, using "off the shelf parts", any of:
There are also variations on the last theme; for example dynamically-allocated simulated multidimensional arrays can be "ragged" (each row can have a different number of allocated columns).
All of these techniques are reasonably straightforward and very widely used.
Steve Summit (talk) 02:49, 11 December 2005 (UTC)
In all honesty I find the example of converting a multidimensional array to an array of structs not only unnecessarily long and drawn out, but also misled. Multidimensional arrays should never be used as arrays of records; this may or may not be obvious, but in any case, multidimensional arrays have perfectly legitimate uses, such as representing matrices, that have nothing to do with structs, and it was for these purposes that they were designed.
Much of the material in the example perhaps should be in the article somewhere, or some other article, but its current placement isn't useful. In particular, constructors and destructors as used in C are a practice, and are not relevent to the C language per se. The same is true of the previous content I added related to creating dynamic arrays, which I admit now is misplaced. There are dozens of mentionable practices in C, including placing constants on the left side of equality comparisons, Duff's device, arrays that extend off the end of records, setting pointers to deallocated objects to NULL, parenthesizing macro arguments, and so on.
In short, if we are really to tabulate C practices, this should either be done in a separate section, or eventually, a separate article. Let storage talk about the basics of storage as built in to the language itself. Keep common practice cleanly separated from core language features. I am prepared to make this change. Is there any opposition? Deco 04:08, 31 Oct 2004 (UTC)