Talk:C (programming language)/Archive 9
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 5 | ← | Archive 7 | Archive 8 | Archive 9 | Archive 10 | Archive 11 | → | Archive 15 |
Any suggestion to improve?
I've added my website [1][c-programming-guide.com] to the tutorial session, but it has been removed. Any suggestions for me to improve my website? —Preceding unsigned comment added by 155.69.5.236 (talk) 14:08, 31 August 2007 (UTC)
- In general, it is not proper for anyone to add their own web site to any article. -- wrp103 (Bill Pringle) (Talk) 05:56, 1 September 2007 (UTC)
originally used vs predominantly used
There has been a back and forth discussion about whether the intro should state that C was "originally used" or "predominantly used" for systems software. There is no doubt that C was originally used for systems software, but the question is if it is now "predominantly" used for systems or application software. The two citations following that sentence say that it was originally used for systems software, but I couldn't find any claim that it is now predominantly used for either.
It might be that C is now mostly used for applications, but until we can find a citation that makes that claim, it seems to me the sentence should use "originally." If we find a citation that says C is mostly used for application software, then I suggest that we change the sentence to:
- Although originally<ref>original footnotes</ref> used for [[system software]], it is now predominantly<ref>new citation</ref> used for [[applications]].
Comments? -- wrp103 (Bill Pringle) (Talk) 15:57, 2 October 2007 (UTC)
- You have misstated the issue. The intent of the sentence is to indicate what C is most useful for, and that is unquestionably systems programming, which is indeed what it was originally designed for. Of course it has been used for applications also, especially on early Unix systems which offered few viable alternatives (typically only Fortran and Bourne shell). These days, however, most apps are coded in higher-level languages such as Perl, PHP, TCL, and C++. C remains the predominant systems implementation language; more often than not those higher-level languages and their run-time libraries are themselves coded in C. C is heavily used for embedded systems development, especially for the scheduling/IPC/device/interrupt support.
- The introductory sentence needs to convey this fundamental aspect of C usage. Your change to "originally" gives an impression that is contrary to the reality; it makes the reader think that although C started out being used for systems programming, its use has changed over time to mainly applications. Rather the opposite has occurred; while a significant fraction of C's use shortly after its invention was for apps, that fraction has become smaller in recent times, due in large part to the more convenient and effective facilities offered by higher-level languages.
- If the references don't properly reflect this, then better references are needed, not a change to the text to give the reader a wrong impression. — DAGwyn 23:01, 2 October 2007 (UTC)
- If somebody can find a reliable source that states whatever C is mostly used for, we can use it. I don't read the sentence the way you are interpreting it. I will tweak it to reduce that conception. However, I stand by the fact that the citation only states that C was originally used for system programming, and until we can find another citation, we can't state what it is usually used for today. -- wrp103 (Bill Pringle) (Talk) 00:35, 4 October 2007 (UTC)
- I agree with wrp103 (Bill Pringle). Derek farn 07:21, 4 October 2007 (UTC)
- I have further tweaked the sentence; hopefully it will now satisfy all interested parties. C has always been used for both systems and applications. It is certainly not the best choice for most modern applications, and has largely been supplanted by Perl, Python, C++, and other languages in that capacity. However, it remains very important for systems implementation, not having been supplanted in general in that area (despite having some deficiencies). My concern with the previous revisions is that they could easily have been read as saying "C was once used mainly for systems programming, but is now more often used for applications", which gives an entirely wrong impression. — DAGwyn 20:16, 4 October 2007 (UTC)
Array-pointer interchangeability error?
In the array-pointer interchangeability section, the four "equivalent" examples at the bottom are not necessarily equivalent, and do not attempt to demonstrate the same point as the rest of the section.
Contrary to what the example suggests, *(x + i) will result in an address (x + i*sizeof(*x)), whereas *(i + x) will result in an address (i + x*sizeof(*i)). Clearly, if sizeof(*x) and sizeof(*i) are not both equal to one, these will not be equivalent.
Also, I'm not even sure if this is really valid C (I can't get it to compile with either MSVC or gcc without casting), since "x designates an array". Either way, this example does not belong in this section. —Preceding unsigned comment added by 69.245.208.25 (talk) 04:25, 5 October 2007 (UTC)
- The article text is correct. i+x does *not* result in an address i+x*sizeof(*i); subclause 6.5.6 of the current C standard explains what happens. The pointer operand is treated the same way in this regard, no matter which order the operands have. The example also strictly conforms to the C standard. I don't know why you didn't get it to work, but try the following strictly conforming program:
#include <stdio.h> static int i = 3; static double x[10]; /* x designates an array */ static void dump() { int k; for (k = 0; k < 10; ++k) printf("%g%c", x[k], k<9? ' ': '\n'); } int main() { dump(); x[i] = 1; dump(); x[i] = 0; dump(); *(x + i) = 1; dump(); *(x + i) = 0; dump(); *(i + x) = 1; dump(); *(i + x) = 0; dump(); i[x] = 1; /* strange, but correct: i[x] is equivalent to *(i + x) */ dump(); return 0; }
The example certainly does belong in the section, since it illustrates the exact meaning of i[x] in C, which is quite unlike most other languages. —Preceding unsigned comment added by DAGwyn (talk • contribs) 15:24, 5 October 2007 (UTC)
C99 Expanded to its own page
I am interested in expanding the C99 section to its own page and including code snippets. The one on this page can stay as is with a pointer to the new page for more details. Does that sound good to you? Daniel.Cardenas 22:00, 14 October 2007 (UTC)
- What would be the purpose? Especially of "code snippets"? Of course, if there were to be a separate C99 page we would plant a link to it in the C page. — DAGwyn 05:04, 15 October 2007 (UTC)
- Better more detailed explanation of C99 changes. Daniel.Cardenas 13:59, 15 October 2007 (UTC)
- So I guess you'd want a link after the list in C99/New features? Note that apart from new features, there were very few substantive changes from the previous spec (C90). The main one worth noting is the removal of implicit "int" in declarations. ("long x;" is still OK, but "register x;" isn't.) — DAGwyn 16:07, 15 October 2007 (UTC)
- Better more detailed explanation of C99 changes. Daniel.Cardenas 13:59, 15 October 2007 (UTC)
Developer - Dennis Ritchie only ?
Well i believe that this was not only Dennis Ritchie. But also Ken Thompson who initiated and developed for example ++ -- unary operators with it's position relative application. In papers i read from Dennis there was Ken "everything" Ken "everywhere", well there are only 2 links to him. It feels to me like he is somehow forgotten, isn't he? Cc..aa..ll (talk) 10:14, 8 December 2007 (UTC)
- The Bell Laboratories team that developed Unix discussed a lot of ideas among themselves, and a suggestion by one person might be developed by another. The initial development of C is generally attributed to Dennis Ritchie, with some later additions due to Steve Johnson. Ken Thompson changed to C instead of assembly language for the Unix kernel only after structures were added to the language. Thompson is given primary credit for developing Unix; he also was co-developer of the chess machine Belle and produced the kernel for Plan 9. — DAGwyn (talk) 19:06, 10 December 2007 (UTC)
- I should add that Dennis Ritchie co-developed Unix, primarily its I/O components. — DAGwyn (talk) 21:02, 12 December 2007 (UTC)
- My C book tells me that "C was the language that was being written to write Unix in, and the developement of each had a strong impact on the other" (paraphrasing, can't find the book). Ofcourse, that may be really wrong, but that's what's roughly there. Martijn Hoekstra (talk) 21:07, 12 December 2007 (UTC)
- I should add that Dennis Ritchie co-developed Unix, primarily its I/O components. — DAGwyn (talk) 21:02, 12 December 2007 (UTC)
- Several versions of Unix were written (developed) before C existed, and the early Unix kernels were written in assembly language (first on the PDP-7, then on the PDP-11); see the history in the Unix article. The only general-purpose programming languages supported in the first edition of Unix were assembly language, B, a dialect of Basic, and a subset of FORTRAN. P. J. Plauger developed a "super-assembler" for the PDP-11 contemporaneously with Ritchie's development of C; both of these were meant to better support systems programming. B, which might have served in this capacity, had the problem of being entirely word-oriented, so it was unable to effectively exploit the PDP-11's byte-oriented features. As I mentioned previously, once data structures ("struct" types) were added to C (as it kept evolving), Ken decided to recode the Unix kernel into C. There is no doubt that due to the close proximity of these workers there was much interaction among them (as I noted previously); however, specific portions of the Unix environment were the responsibility of particular individuals, who made the design decisions and personally coded the products. Thus, C belonged to Dennis, and most of the Unix kernel (excluding I/O components) belonged to Ken. In "user space", the various commands, utilities, libraries, etc. belonged to various people; for example there were several early attempts at what eventually became the "standard I/O library"; one due to Mike Lesk, with Dennis providing the one that eventually prevailed. — DAGwyn (talk) 22:21, 12 December 2007 (UTC)
- I will add that Ken was the original developer of the B language, but its role in the evolution of C starts with the B compiler that Dennis wrote; see the B article for more about the history. Much of C's syntax was inherited from B, and its influence is noted in the C article. — DAGwyn (talk) 23:32, 12 December 2007 (UTC)
- Wow, thanks for all the infomation. Though not exactly what talkpages are meant for, it was a rather good read! Martijn Hoekstra (talk) 23:33, 12 December 2007 (UTC)
So what did Kernighan do ? Reg nim (talk) 18:17, 13 May 2008 (UTC)
- Kernighan has written a number of books about C and Unix, including K&R. He also contriuted to Unix, including awk, nroff and troff. -- wrp103 (Bill Pringle) (Talk) 22:45, 13 May 2008 (UTC)
- Many thanks. Reg nim (talk) 11:47, 14 May 2008 (UTC)
Closures?
In the section "Characteristics" is the phrase "function pointers allowing for a rudimentary form of closures and runtime polymorphism." I'm pretty certain that it's not possible to call these function pointers "closures." A closure (computer science) is defined as a function combined with a context or environment. Since C doesn't allow nested functions (extensions to the standard excepted), a traditional closure is not possible without trickery like (ab)use of the the preprocessor, or an explicit passing of variables to the function. I could be mistaken here, but I don't think so. I'd really like to change that sentence to be more correct. Any suggestions? Foolingmachine (talk) 03:22, 11 January 2008 (UTC)
- It doesn't say that function pointers are closures, it says they can be used in implementing a rudimentary form of closures, which seems to be correct. It may also be necessary to employ static variables (corresponding to "bound" variables). I don't think there is any need to revise the wording. — 158.12.88.57 (talk) 18:07, 11 January 2008 (UTC)
- That is true, and I see your point. I still think the wording could be revised, as it doesn't give any explanation of how this is possible, nor is this common knowledge (I'd venture that the majority of C programmers don't know what closures are anyway). Another issue I take with the phrasing is that I commonly see anonymous functions mistakenly called "closures." I don't want to further propagate that mistake. I do recognize I'm hardly an authority on the matter, of course. Foolingmachine (talk) 09:57, 12 January 2008 (UTC)
- It is fairly common for OS or library APIs to allow the user to pass a callback function and a void* that will be passed to the callback when it is called. Most experienced C programmers will have seen one or more of those, even though they don't know that what they're doing would be called a "closure" if there were language support for doing it more transparently. It is not too far off to describe it as "a rudimentary form of closures", I think. Also it is not clear to me who you think the article supports the notion that closures means anonymous functions, when C does not have anonymous functions at all. –Henning Makholm 21:49, 12 January 2008 (UTC)
- Again, fine points. From a functional programming standpoint, it simply seems highly odd that such a sentence is included with virtually no explanation whatsoever. It is not a common way to refer to C function pointers, even if the essential pieces are there (your void* could certainly be considered a method of passing the necessary context, but it's stretching the definition, I think). After all, none of the explanations presented on this talk page appear in the article. As for the "anonymous functions" bit, I wasn't very clear or correct—the bottom line is that closures are commonly misunderstood, and this phrase doesn't really provide any useful information. I can still see no valid reason to include it in the article, at least in the current form. Foolingmachine (talk) 03:14, 14 January 2008 (UTC)
- I agree that it is strange for the sentence to be there; it would be better for the article to describe what function pointers are than to hint obliquely what they may be used for. (However, again, I don't think that the strange sentence claims that function pointers can be referred to as closures, only that they can be used as one of several building blocks for implementing closures. Don't you see the difference between those?) –Henning Makholm 03:24, 14 January 2008 (UTC)
- Again, fine points. From a functional programming standpoint, it simply seems highly odd that such a sentence is included with virtually no explanation whatsoever. It is not a common way to refer to C function pointers, even if the essential pieces are there (your void* could certainly be considered a method of passing the necessary context, but it's stretching the definition, I think). After all, none of the explanations presented on this talk page appear in the article. As for the "anonymous functions" bit, I wasn't very clear or correct—the bottom line is that closures are commonly misunderstood, and this phrase doesn't really provide any useful information. I can still see no valid reason to include it in the article, at least in the current form. Foolingmachine (talk) 03:14, 14 January 2008 (UTC)
- As I recall, the bit about "closures" was already present before I started editing this article. I don't see the necessity to mention it, but presumably the original proponent had his reasons. — DAGwyn (talk) 05:10, 13 January 2008 (UTC)
- It is fairly common for OS or library APIs to allow the user to pass a callback function and a void* that will be passed to the callback when it is called. Most experienced C programmers will have seen one or more of those, even though they don't know that what they're doing would be called a "closure" if there were language support for doing it more transparently. It is not too far off to describe it as "a rudimentary form of closures", I think. Also it is not clear to me who you think the article supports the notion that closures means anonymous functions, when C does not have anonymous functions at all. –Henning Makholm 21:49, 12 January 2008 (UTC)
- That is true, and I see your point. I still think the wording could be revised, as it doesn't give any explanation of how this is possible, nor is this common knowledge (I'd venture that the majority of C programmers don't know what closures are anyway). Another issue I take with the phrasing is that I commonly see anonymous functions mistakenly called "closures." I don't want to further propagate that mistake. I do recognize I'm hardly an authority on the matter, of course. Foolingmachine (talk) 09:57, 12 January 2008 (UTC)
- I spotted this prior to reading this Talk and fixed it. The text really did seem to be claiming that function pointers are primitive closures. Though it's hard to pin down an exact definition of a closure, it has to do with the construction of a run-time object that encapsulates access to a captured lexical environment, plus code. C function pointers are the code only. You can't use C pointers to do closures, period; there is no standard-defined access to the lexical environment. Thanks to Turing equivalence, you can emulate the behavior, which isn't the same thing as expressing it. The page is already several times longer than a proper article, so there is no need to get into details about what features of other programming languages can or cannot be emulated using function pointers. A C example of emulating closures with function pointers might be appropriate in the Wikipedia page on closures, to which this article could point.
Relation of {} to set theory?
I always felt it is taken or inspired from here. It helped me to lear a C language (Anyway it is used for for example ordered set of statements, ordered set of "data structures" in declarations ... ). I recently ran into discussion that those 2 symbols have nothing to do with set theory. Could someone correct this? Xchmelmilos (talk) 22:33, 26 February 2008 (UTC)
- In mathematics, are used for sets - is the set containing 1, 2 and 3; is the set of positive reals, etc.
- In C however, braces are not used for sets, just compound statements and initializers, etc... but Oberon does use braces for sets (and
BEGIN
andEND
for blocks) and Pascal uses braces for comments. - Alksentrs (talk) 15:20, 28 February 2008 (UTC)
- There is a kind of set-like use of braces in structure declarations, but really it is better thought of as a syntactic grouping construct than anything else, for C. —Preceding unsigned comment added by DAGwyn (talk • contribs) 17:34, 29 February 2008 (UTC)
- The { } symbols can be used to define an array of elements (not a set) like this: int a[] = { 1, 29, 6 ,8 }; L337 Krew (talk) 13:43, 7 May 2008 (UTC)
- Yes, that may have inspired their use in initializer lists, but not for compound statements. — DAGwyn (talk) 20:24, 8 May 2008 (UTC)
- Also keep in mind that braced sets in modern math notation are unordered, whereas everything you put braces around in C is ordered, so this is a misleading analogy. There's certainly no basis for claiming C was designed with this analogy in mind. Dcoetzee 21:53, 8 May 2008 (UTC)
- You're loony. C braces have next to nothing to with sets, semantically. I can't fathom what sort of learning difficulty with C could possibly be resolved by identifying braces with set notation. Gee, you know, I'm an astronomer. A double-pointer int (**x)(void) looks like a binary star system, which is something warmly familiar and helped me learn C ...
Archive 2 created
All the discussions had died off, and the page was way too long. — DAGwyn (talk) 00:38, 15 April 2008 (UTC)
- I've gone through the archives and split them into reasonably-sized chunks. Thanks to the lack of housekeeping in the early days the first 4 pages or so are very poorly chronologically ordered (the very earliest discussion is on pages 3 and 4), but at least it's feasible to read through the old discussion now. I'll try to stay on top of this in future. Chris Cunningham (not at work) - talk 09:49, 1 May 2008 (UTC)
"Blather" and article introductions
So for the second time the tooshort tag was removed from the article with the addition of a "blather" which reads, in its entirety:
This article traces the evolution of C and describes its characteristics.
In addition, the summary for the edit made this observation:
The ToC serves just fine as a detailed article preview
This demonstrates a misunderstanding of WP:LEAD, and of the makeup and function of introductiory sections in Wikipedia articles in general.
Quoting from the summary of that style guideline:
The lead should be able to stand alone as a concise overview of the article. It should establish context, summarize the most important points, explain why the subject is interesting or notable, and briefly describe its notable controversies, if there are any.
The purpose of the lead section is not to serve as a foreword, or to describe in terms of the encyclopedia itself what the article is about. It is to serve as an effective summary and overview of the article's key points, such that reading the introduction provides one with a reasonable high-level understanding of the subject matter as if one had skimmed the article itself.
In this capacity, the current lead is inadequate. Beyond providing context (a literal description of what the article defines), it provides only one sentence to capture the importance of the language in its field. For an article of this length, we should be aiming for three paragraphs which provide a concise but complete summary of the article's key points without explicitly saying that the user has to read the article for further detail.
If we can't get this sorted out shortly, the article should be re-tagged so that it is adding to the appropriate cleanup category. That lets users interested in cleanup tasks know that there's work needed here. Chris Cunningham (not at work) - talk 10:57, 1 May 2008 (UTC)
- The problem is, when in the past the lead included other (factual) "orienting" statements such as "C is one of the most widely used programming languages", proponents of other PLs (and critics of C) jumped all over it. The current lead is a compromise that was worked out long ago and it has remained very stable since then. It does perform the essential functions of a lead: it defines the subject, it explains its significance in the world, and it states the scope of the article. I see no point in trying to turn it into a "capsule article", since the text would become unintelligible if significantly abridged for that purpose. — DAGwyn (talk) 16:11, 1 May 2008 (UTC)
- I could go either way. I think for C a short introduction is sufficient - but the current introduction surely understates the impact of C of both industry and research. As for critics of C "jumping all over it," I wrote the original criticism section on C and would still advocate an introduction emphasizing its impact. Dcoetzee 17:24, 1 May 2008 (UTC)
- Thanks for the commentary. I suggest we work on an expanded introduction in this Talk page until a mutually acceptable version results. — DAGwyn (talk) 23:15, 2 May 2008 (UTC)
Update
I've done some minor expansion which provides a skeleton for further work. Chris Cunningham (not at work) - talk 12:49, 22 June 2008 (UTC)
Upper case
Mdsawyer58 has twice changed the identifiers in the original example
long int SomeFunction(); /* int OtherFunction(); */ /* int */ CallingFunction() { long int test1; register /* int */ test2; test1 = SomeFunction(); if (test1 > 0) test2 = 0; else test2 = OtherFunction(); return test2; }
to e.g. some_function
on the grounds that "Historically, as stated by K&R in "The C Programming Language" manual (pg 33), uppercase is used for symbolic constants. I believe this page should be presented historically accurate." This reflects a couple of misunderstandings, which I will explain here in the hope of averting an editing war. K&R was talking about constructs like #define MAXLINE 80
, where indeed all-upper case is used for a symbolic constant. That does not by any means imply that upper-case characters must not appear anywhere else in source code! It might be taken as implying that identifiers consisting solely of upper-case characters ought not to be used for anything other than symbolic constants. The above example does not violate any of these conventions.
(Indeed, it illustrates a common and useful C style that is even more widely used in C++ and Pascal. It is good from the point of view of exposition to show that C identifiers, for variables and functions in this example, are not limited to lower case.) Note also that the example is valid as-is under the C compilers available at the time K&R was published, and was newly invented for this article. Therefore there is no error with regard to "historical accuracy." — DAGwyn (talk) 18:33, 11 July 2008 (UTC)
CSS
I noticed that CSS was added to the list of languages influenced by C in this edit. CSS is a markup language, and its syntax is quite different from C. Is there any reference to support the influence of C here? Papa November (talk) 18:31, 27 July 2008 (UTC)
- I doubt it. I've removed it for now; we don't need to keep dubious information around while a reference is found. Chris Cunningham (not at work) - talk 19:49, 27 July 2008 (UTC)
Picture
What happened to the picture of the K&R C programming book in the summary box at the top of the page I didn't see it in the revisions at all --Melab±1 21:33, 9 September 2008 (UTC)
- As I recall, somebody decided that it didn't meet Wikipedia requirements for photographic images, i.e. it wasn't copyright-free. — DAGwyn (talk) 00:04, 13 September 2008 (UTC)
Why is the 2nd edition shown, without mentioning earlier versions? I have the 1st edition (printed in 1978), as well as copies of the earlier "Reference Manual" which was an on-line file. (I also have some X3J11 notes, from when I was an Observer Member.) Should I try to include some of this stuff in Wikipedia? Tripodics (talk) 23:51, 29 March 2009 (UTC)
Howcome no syntax highlighting?
Not a very important point, but surely we should be using the <source lang="c"></source> tags in this article, otherwise why does Wikipedia have support for them? Was there a previous discussion on this? --Huffers (talk) 17:55, 27 September 2008 (UTC)
- Ah, found it. I'm amazed people were against it. Given the most popular IDE's and text editors used for coding C all have syntax highlighting on by default, you'd have thought this would imply that most people find syntax highlighted code easier to read. --Huffers (talk) 18:08, 27 September 2008 (UTC)
- Not everyone - it appears to be a preference rather than an absolute rule. It's been discussed several times (and see that there are several people to convince). Tedickey (talk) 18:41, 27 September 2008 (UTC)
- Perhaps this article should have an editnotice to inform anyone editing it about the current consensus on source tags, so they don't keep getting put in and then reverted? Joseph Myers (talk) 20:05, 27 September 2008 (UTC)
- While were on the subject, why is this exclusive to C? The same things could be said about most programming languages(if not all). Mike92591 (talk) 21:02, 27 September 2008 (UTC)
- I'd suppose that making it a settable user preference would make more people happy with it - but look at the mess with dates, which are settable in principle. Tedickey (talk) 21:26, 28 September 2008 (UTC)
The main arguments against lang=c source tags are (a) the result looks horrible! in many browsers; (b) readability is actually reduced when more information is visually presented; (c) color is not part of the language; (d) such tags are of no value to a competent C programmer. For small code examples, whatever benefit is claimed for the coloration cannot be very significant anyway. — DAGwyn (talk) 10:38, 9 November 2008 (UTC)
Absent features
This really could go on and on. I think it would make more sense to just say what its features are. Mike92591 (talk) 20:17, 28 September 2008 (UTC)
- Actually the list is a meager remnant of the now-vanished Criticism of C (programming language) article. It serves a useful purpose under the section on Minimalism. — DAGwyn (talk) 10:41, 9 November 2008 (UTC)
operators
operators explain in c language —Preceding unsigned comment added by 164.100.6.50 (talk) 10:24, 7 October 2008 (UTC)
- I guess you're looking for Operators in C and C++. Alksentrs (talk) 11:43, 7 October 2008 (UTC)
- Somebody removed the section that listed them, which I have now restored (it contains the link mentioned above, which goes into more detail). — DAGwyn (talk) 10:46, 9 November 2008 (UTC)
Added first line
i added first line because the first line is very well not a good beginning. The beginning should be an introduction to comp language C.Albertgenii12 (talk) 21:16, 21 October 2008 (UTC)
"Array types in C are always one-dimensional"
Surely this is just wrong. I just wrote a little program to check I wasn't going mad and prove that you can have 2+-dimensional arrays in C. And it works:
[BTW No-one need bother pointing out the lack of variable initialisation!]
#include <stdio.h> typedef char array[10][10]; void main(void) { array test; int x,y; for (x=0; x<=9; x++) { for (y=0; y<=9; y++) printf("%3d ",test[x][y]); printf("\n"); } }
RobertSteed (talk) 16:30, 18 November 2008 (UTC)
- Read a bit further down. "C does not have a special provision for declaring multidimensional arrays, but rather relies on recursion within the type system to declare arrays of arrays, which effectively accomplishes the same thing. The index values of the resulting "multidimensional array" can be thought of as increasing in row-major order." I'm skeptical about this interpretation, but without carefully consulting the standard I'm not prepared to contest it. Dcoetzee 21:29, 18 November 2008 (UTC)
I did read that, and it too is wrong. Again, see my example - that is a multidensional array, in standard C code. It is not an array of arrays.
RobertSteed (talk) —Preceding undated comment was added at 11:26, 19 November 2008 (UTC).
- Your example is wrong.
- That is an array of arrays.
- Consider what sizeof test[x] means. —Preceding unsigned comment added by 216.239.45.4 (talk) 11:41, 1 March 2009 (UTC)
- It is a matter of interpretation. However often used, an array in C is veneer ("syntactic sugar)" over plain pointer arithmetic. The way it handles multidimensional arrays is to extend that pointer arithmetic. So, in fact, C does not have any special provision for multidimensiaonal arrays. However, as far as I'm concerned, the same could be said for one-dimensional arrays in C. I see no point in the statement saying "they're always one-dimensional". I'm for deleting that. --A D Monroe III (talk) 12:11, 19 November 2008 (UTC)
- Me too - you might as well say C doesn't really have array indexing, since it's just syntactic sugar for pointer arithmetic and dereferencing. It was designed to support multidimensional arrays in this way. Dcoetzee 20:40, 19 November 2008 (UTC)
- The array indexing operator
[]
is just veneer over pointer arithmetic. Arrays themselves are not. Eric119 (talk) 00:25, 20 November 2008 (UTC)
- The array indexing operator
Eric119 is right; and furthermore, the fact that C arrays are inherently one-dimensional is important for a programmer to understand, as it affects function parameters (for example). — DAGwyn (talk) 17:53, 6 May 2009 (UTC)
- As a side note, it is important to see that there is a difference between a 2 dimensional array like char arr[10][10] (which does rely on recursion), and a 2 dimensional array where the first dimension is an array of pointers to the second dimension. A good example of the latter is argv (the 2nd argument to main, the argument vector). The simple 2 dimensional uses less memory, and is generally consecutive in memory - the second uses more memory (the size of the first dimension) and may or may not be consecutive in memory Ajrisi (talk) 13:01, 12 May 2009 (UTC)