Jump to content

Talk:C (programming language): Difference between revisions

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
Content deleted Content added
comment
m Reverted 1 edit by 105.161.216.244 (talk) to last revision by Favonian
 
(48 intermediate revisions by 28 users not shown)
Line 1: Line 1:
{{Skip to talk}}
{{Skip to talk}}
{{Talk header|search=no|noarchive=yes}}
{{Talk header|search=no|noarchive=yes}}
{{WikiProject banner shell|1=
{{WikiProject banner shell|class=C|vital=yes|1=
{{WikiProject Computing |class=C |importance=Top |software=y |software-importance=Top |science=y |science-importance=High}}
{{WikiProject Computing |importance=Top |software=y |software-importance=Top |science=y |science-importance=High}}
{{WikiProject Computer science |class=C |importance=High}}
{{WikiProject Computer science |importance=High}}
{{WikiProject C/C++ |class=C |importance=Top |c=yes}}
{{WikiProject C/C++ |importance=Top |c=yes}}
}}
}}
{{Vital article|level=4|topic=Technology|class=C}}
{{ArticleHistory
{{ArticleHistory
|action1=FAC|action1date=2004-03-15, 02:35:04 |action1link=Wikipedia:Featured article candidates/C (programming language)|action1result=promoted|action1oldid=2774835
|action1=FAC|action1date=2004-03-15, 02:35:04 |action1link=Wikipedia:Featured article candidates/C (programming language)|action1result=promoted|action1oldid=2774835
Line 26: Line 25:
{{archives|bot=MiszaBot I|search=yes|age=100|dounreplied=yes}}
{{archives|bot=MiszaBot I|search=yes|age=100|dounreplied=yes}}


== improving the "hello world" example ==


Rather than an blind "afaik", a [[WP:RS|reliable source]] is needed to alter an example which has a valid reliable source. [[User:Tedickey|TEDickey]] ([[User talk:Tedickey|talk]]) 10:15, 22 October 2023 (UTC)


:'''Give in''': Meanwhile, I checked the program using gcc 11.4.0 under Ubuntu. It seems the a missing <code>return</code> leads to a warning - ''except'' in <code>main()</code>, so {{u|Tedickey}} is right. As a side remark, I don't see a source given for the 2nd version. - [[User:Jochen Burghardt|Jochen Burghardt]] ([[User talk:Jochen Burghardt|talk]]) 10:21, 22 October 2023 (UTC)
== Delete the "middle-level language" part ==


::Quoting from ''ISO/IEC 9899:1999(E)'', section 5.1.2.2.3 '''Program termination''':
It's bound to cause confusion on to the nature of C as somewhere between a high-level and low-level language, especially since [[Low-level programming language#Assembly language|Low-level programming language #Assembly language]] names it as a high-level language. One could also argue that middle-level is a fairly vague term that could have a lot of different interpretations. [[User:Gvv57348|Gvv57348]] ([[User talk:Gvv57348|talk]]) 18:06, 11 December 2022 (UTC)
<blockquote>If the return type of the main function is a type compatible with int, a return from the initial call to the main function is equivalent to calling the exit function with the value returned by the main function as its argument; reaching the '''}''' that terminates the main function returns a value of 0.
</blockquote>
::Perhaps C11 changes that, but again, a [[WP:RS]] helps [[User:Tedickey|TEDickey]] ([[User talk:Tedickey|talk]]) 15:19, 22 October 2023 (UTC)


::Regarding the comment that a diagnostic is required: I don't see that in the standard. Perhaps it's another instance of people confusing a particular implementation with the standard [[User:Tedickey|TEDickey]] ([[User talk:Tedickey|talk]]) 15:35, 22 October 2023 (UTC)
:[[WP:DIY]] You may have a good point, IMHO. [[User:Chumpih|<span style="text-shadow: 2px 2.5px 3px #448811bb">Chumpih</span>]] <sup>[[User talk:Chumpih|t]]</sup> 20:14, 11 December 2022 (UTC)
:
::BTW, WP has articles [[Low-level programming language]] and [[High-level programming language]], but no such thing for middle level (this could have possibly been [[WP:OR]]). — [[User:Vincent Lefèvre|Vincent Lefèvre]] ([[User talk:Vincent Lefèvre|talk]]) 14:13, 12 December 2022 (UTC)
:::The only way you can @[[User:Gvv57348|Gvv57348xv]] has [[Special:Contributions/108.75.76.176|108.75.76.176]] ([[User talk:108.75.76.176|talk]]) 04:17, 14 May 2023 (UTC)


== Mention of C allowing various memory allocations schemes ==
==Wiki Education assignment: Linguistics in the Digital Age==
{{dashboard.wikiedu.org assignment | course = Wikipedia:Wiki_Ed/University_of_Arizona/Linguistics_in_the_Digital_Age_(Spring_2023) | assignments = [[User:ManD01n|ManD01n]] | start_date = 2023-01-11 | end_date = 2023-05-11 }}


{{u|Jochen Burghardt}} [https://en.wikipedia.org/enwiki/w/index.php?title=C_(programming_language)&diff=prev&oldid=1183993545 removed] this section on C allowing various memory allocation implementations:
<span class="wikied-assignment" style="font-size:85%;">— Assignment last updated by [[User:Nurbekyuldashov|Nurbekyuldashov]] ([[User talk:Nurbekyuldashov|talk]]) 01:52, 9 May 2023 (UTC)</span>


:{{tq|C permits the use and implementation of different [[C dynamic memory allocation|memory allocation]] schemes, including a typical {{code |lang=c |malloc}} and {{code |lang=c |free}}; a more sophisticated mechanism with [[Region-based memory management|''arenas'']]; or a version for an [[kernel (operating system)|OS kernel]] that may suit [[direct memory access|DMA]], use within [[interrupt handler]]s, or integrated with the [[virtual memory]] system.}}
== C is a system language, not general purpose ==


With the edit summary {{tq|"malloc is not built in in C, but a library function, and could be provided for every other language in a similar way"}}. It's actually not true that you can do this in every other language, it depends on directly manipulating and storing pointers for one thing, which most languages do not do. The passage doesn't say malloc is part of C itself, in fact it implies the opposite - it lists malloc as one possibility. I disagree with this removal. [[User:DIYeditor|—DIYeditor]] ([[User talk:DIYeditor|talk]]) 19:49, 7 November 2023 (UTC)
C has system facilities. Any language with low-level facilities should not be use for general-purpose programming. It bakes in dependencies, results in lock in (which C does), and also results in inflexibility.


:As I understand the title of this article, it is about the C programming language itself; there is a different article [[C standard library]]. "{{tq|The passage doesn't say malloc is part of C itself}}" - this is the reason why I think it shouldn't be discussed here, but at [[C standard library]]. As a side remark, <code>malloc</code> can be implemented as is in every language that supports pointers, and with slight modifications in every language that supports arrays (having arbitrary type casts in the language will increase user convenience). - [[User:Jochen Burghardt|Jochen Burghardt]] ([[User talk:Jochen Burghardt|talk]]) 11:58, 8 November 2023 (UTC)
C also has many primitive facilities like pointers and defines which really have no place in general-purpose programming. [[User:Ian.joyner|Ian.joyner]] ([[User talk:Ian.joyner|talk]]) 20:12, 13 May 2023 (UTC)
::Please stop edit warring to restore your preferred version.
::We can wait for input from more people. [[User:DIYeditor|—DIYeditor]] ([[User talk:DIYeditor|talk]]) 13:17, 8 November 2023 (UTC)
:::I didn't edit [[C (programming language)]] after my above reply. The anonymous IP 193.162.48.193 vandalized an article part that is unrelated to our above discussion, and I assure that it wasn't me. Admittedly, my 2nd revert might have violated a strict interpretation of [[WP:BRD]]; however, I gave a long justification in my edit summary. Waiting for opinions from other people is ok for me. - [[User:Jochen Burghardt|Jochen Burghardt]] ([[User talk:Jochen Burghardt|talk]]) 14:05, 8 November 2023 (UTC)
::The goal of this the overall section is to explain and justify the wide adoption of C as a systems programming language. The section in question states that C permits choice in dynamic memory allocators - a good justification, since operating systems and similar often control memory for other processes. Options range from the usual {{code|stdlib.h}} to very machine-specific ones. This flexibility is a feature of the language. Only one of the choices pertains to the standard library and its {{code|malloc}} - the others do not - and indeed there is already a link in the debated section to [[C dynamic memory allocation]].
::If there are improvements to be made, then let's make them! But I agree with {{u|DIYeditor}} and disagree with the removal. [[User:Chumpih|<span style="text-shadow: 2px 2.5px 3px #448811bb">Chumpih</span>]] <sup>[[User talk:Chumpih|t]]</sup> 20:18, 8 November 2023 (UTC)


== Duplicate sections on related languages - merge? ==
:I see you put this on [[Talk:C++]] as well; it is generally wrong, and I'll reply to both comments here. [[General-purpose programming language]] is a specific term contrasted with domain-specific languages. C is a general-purpose programming language and you will find this present in nearly any source that discusses it. For instance, the very first sentence of K&R (2nd ed.) says "{{tq|C is a general-purpose programming language.}}" (page 1; also a near identical sentence is in the preface on p. xi).
:The Uses section is a mess and needs some serious cleanup, but it's valid to discuss how it is used; C is widely used outside of systems programming contexts, though, so this change would also be invalid there. Wikipedia is an encyclopedia and [[WP:NOTMANUAL|not a manual]]; it would be inappropriate for the article to present an opinion on where C should be deployed in wiki-voice.
:It ''might'' be appropriate to present opinions on current usage of C (and C++, in that article). There are several experts in the field who have expressed concerns specifically related to memory safety with the wide deployment of programs written in C and C++—this is far from a universally held opinion though. Note that this would require more research to incorporate; my off-the-cuff anecdote isn't enough, and any change would want to assess appropriate sources (ideally, highly trustworthy secondary sources, especially ones that provide general overviews of the state of the art, such as instructional textbooks). [[User:Dylnuge|<span style="color: #1e79a1;font-weight:700;">Dylnuge</span>]] <sup>([[User talk:Dylnuge|''Talk'']] • [[Special:Contributions/Dylnuge|''Edits'']])</sup> 17:29, 1 September 2023 (UTC)


There appears to be two similar sections in the main article: [[C (programming language)#Relations to other languages|Relations to other languages]] and [[C (programming language)#Related languages|Related languages]]. Former is a list within the Overview section; latter is an exposition on the influence of C, sitting near the end of the article.
== "Only the last member stored is valid" ==


Should we consider these as duplicates, and merge them to one location? Or are we happy with the different emphasis on the somewhat similar content, and leave well alone? Or Perhaps replace the first section with a sentence and keep the latter section? Or something else? [[User:Chumpih|<span style="text-shadow: 2px 2.5px 3px #448811bb">Chumpih</span>]] <sup>[[User talk:Chumpih|t]]</sup> 05:29, 26 April 2024 (UTC)
In the "overview" section, under "User-defined (typedef) and compound types are possible" Unions are mentioned as "Union is a structure with overlapping members; only the last member stored is valid."


== C is a compiled language ==
This is not a fair or accurate statement according to the C standard. I believe this may have been written confusing the C standard for the C++ one, in which accessing a union member that was not most recently written to is strictly undefined.


A compiled language is "typically" compiled according to Wikipedia. I would like to add "compiled" to describe C. In fact, C is one of the most common languages, if not the most common language, cited as an example of a compiled language. [[User:Chris.temp.level.0|Chris.temp.level.0]] ([[User talk:Chris.temp.level.0|talk]]) 13:27, 17 July 2024 (UTC)
The C standard explicitly allows "type-punning" using unions, but carefully promises that reinterpreting the bit-representation of one type to another may result in an invalid or trap representation.
:{{ping|Vincent Lefèvre|Jkudlick}} The issue seems to be [[Special:Diff/1233796365|this edit]] which inserted "[[Compiled language|compiled]]" before "[[general-purpose programming language]]" in the lead. Per [[WP:LEAD]], information in the introduction should be a summary of what is in the body of the article and it looks as if one reason given for a revert was doubt about whether the information is in the body. Bear in mind that the lead already refers to "compile" in a couple of places: "C [[compiler]]s" + "designed to be [[compiler|compiled]]" + "can be compiled". People like fiddling and Google tells us that C interpreters exist although of course if the term "compiled language" has any meaning, it certainly applies to C. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 01:43, 18 July 2024 (UTC)

::{{re|Johnuniq|Chris.temp.level.0|Vincent Lefèvre}} I was only involved insofar as this article has pending changes protection and I happened to review a pending change that had already been reverted. As I stated {{diff|diff=prev|oldid=1234287773|label=on my talk page}}, I would have accepted the edit if it had not already been reverted. I am glad to see Chris has engaged in discussion here to reach consensus, and I will leave the discussion to those with much better knowledge of this subject than me. —&nbsp;[[User:Jkudlick|Jkudlick]]&nbsp;&#x2693;&nbsp;[[User_talk:Jkudlick|(talk)]] 23:29, 18 July 2024 (UTC)
The following is pulled directly from the C17 standard. It lies in a footnote under section 6.5.2.3.3:
::{{re|Jkudlick|Johnuniq|Chris.temp.level.0}} I think that "designed to be compiled" already present in the LEDE is sufficient. — [[User:Vincent Lefèvre|Vincent Lefèvre]] ([[User talk:Vincent Lefèvre|talk]]) 12:00, 20 July 2024 (UTC)

:::Agree. [[User:Chumpih|<span style="text-shadow: 2px 2.5px 3px #448811bb">Chumpih</span>]] <sup>[[User talk:Chumpih|t]]</sup> 14:34, 20 July 2024 (UTC)
"If the member used to read the contents of a union object is not the same as the member last used to store a value in the object, the appropriate part of the object representation of the value is reinterpreted as an object representation in the new type as described in 6.2.6 (a process sometimes called “type punning”). This might be a trap representation."

The mention of unions should probably be edited to something like "Union is a structure with overlapping members; it allows multiple data types to share the same memory location".

I will leave this note here for a few weeks and if no one objects I will make the edit. [[User:WillisHershey|WillisHershey]] ([[User talk:WillisHershey|talk]]) 21:28, 25 September 2023 (UTC)

== improving the "hello world" example ==

Rather than an blind "afaik", a [[WP:RS|reliable source]] is needed to alter an example which has a valid reliable source. [[User:Tedickey|TEDickey]] ([[User talk:Tedickey|talk]]) 10:15, 22 October 2023 (UTC)

:'''Give in''': Meanwhile, I checked the program using gcc 11.4.0 under Ubuntu. It seems the a missing <code>return</code> leads to a warning - ''except'' in <code>main()</code>, so {{u|Tedickey}} is right. As a side remark, I don't see a source given for the 2nd version. - [[User:Jochen Burghardt|Jochen Burghardt]] ([[User talk:Jochen Burghardt|talk]]) 10:21, 22 October 2023 (UTC)

::Quoting from ''ISO/IEC 9899:1999(E)'', section 5.1.2.2.3 '''Program termination''':
<blockquote>If the return type of the main function is a type compatible with int, a return from the initial call to the main function is equivalent to calling the exit function with the value returned by the main function as its argument; reaching the '''}''' that terminates the main function returns a value of 0.
</blockquote>
::Perhaps C11 changes that, but again, a [[WP:RS]] helps [[User:Tedickey|TEDickey]] ([[User talk:Tedickey|talk]]) 15:19, 22 October 2023 (UTC)

::Regarding the comment that a diagnostic is required: I don't see that in the standard. Perhaps it's another instance of people confusing a particular implementation with the standard [[User:Tedickey|TEDickey]] ([[User talk:Tedickey|talk]]) 15:35, 22 October 2023 (UTC)

Latest revision as of 11:20, 15 September 2024

Former featured articleC (programming language) is a former featured article. Please see the links under Article milestones below for its original nomination page (for older articles, check the nomination archive) and why it was removed.
Article milestones
DateProcessResult
March 15, 2004Featured article candidatePromoted
July 25, 2006Featured article reviewDemoted
September 9, 2006Good article nomineeNot listed
Current status: Former featured article

improving the "hello world" example

[edit]

Rather than an blind "afaik", a reliable source is needed to alter an example which has a valid reliable source. TEDickey (talk) 10:15, 22 October 2023 (UTC)[reply]

Give in: Meanwhile, I checked the program using gcc 11.4.0 under Ubuntu. It seems the a missing return leads to a warning - except in main(), so Tedickey is right. As a side remark, I don't see a source given for the 2nd version. - Jochen Burghardt (talk) 10:21, 22 October 2023 (UTC)[reply]
Quoting from ISO/IEC 9899:1999(E), section 5.1.2.2.3 Program termination:

If the return type of the main function is a type compatible with int, a return from the initial call to the main function is equivalent to calling the exit function with the value returned by the main function as its argument; reaching the } that terminates the main function returns a value of 0.

Perhaps C11 changes that, but again, a WP:RS helps TEDickey (talk) 15:19, 22 October 2023 (UTC)[reply]
Regarding the comment that a diagnostic is required: I don't see that in the standard. Perhaps it's another instance of people confusing a particular implementation with the standard TEDickey (talk) 15:35, 22 October 2023 (UTC)[reply]

Mention of C allowing various memory allocations schemes

[edit]

Jochen Burghardt removed this section on C allowing various memory allocation implementations:

C permits the use and implementation of different memory allocation schemes, including a typical malloc and free; a more sophisticated mechanism with arenas; or a version for an OS kernel that may suit DMA, use within interrupt handlers, or integrated with the virtual memory system.

With the edit summary "malloc is not built in in C, but a library function, and could be provided for every other language in a similar way". It's actually not true that you can do this in every other language, it depends on directly manipulating and storing pointers for one thing, which most languages do not do. The passage doesn't say malloc is part of C itself, in fact it implies the opposite - it lists malloc as one possibility. I disagree with this removal. —DIYeditor (talk) 19:49, 7 November 2023 (UTC)[reply]

As I understand the title of this article, it is about the C programming language itself; there is a different article C standard library. "The passage doesn't say malloc is part of C itself" - this is the reason why I think it shouldn't be discussed here, but at C standard library. As a side remark, malloc can be implemented as is in every language that supports pointers, and with slight modifications in every language that supports arrays (having arbitrary type casts in the language will increase user convenience). - Jochen Burghardt (talk) 11:58, 8 November 2023 (UTC)[reply]
Please stop edit warring to restore your preferred version.
We can wait for input from more people. —DIYeditor (talk) 13:17, 8 November 2023 (UTC)[reply]
I didn't edit C (programming language) after my above reply. The anonymous IP 193.162.48.193 vandalized an article part that is unrelated to our above discussion, and I assure that it wasn't me. Admittedly, my 2nd revert might have violated a strict interpretation of WP:BRD; however, I gave a long justification in my edit summary. Waiting for opinions from other people is ok for me. - Jochen Burghardt (talk) 14:05, 8 November 2023 (UTC)[reply]
The goal of this the overall section is to explain and justify the wide adoption of C as a systems programming language. The section in question states that C permits choice in dynamic memory allocators - a good justification, since operating systems and similar often control memory for other processes. Options range from the usual stdlib.h to very machine-specific ones. This flexibility is a feature of the language. Only one of the choices pertains to the standard library and its malloc - the others do not - and indeed there is already a link in the debated section to C dynamic memory allocation.
If there are improvements to be made, then let's make them! But I agree with DIYeditor and disagree with the removal. Chumpih t 20:18, 8 November 2023 (UTC)[reply]
[edit]

There appears to be two similar sections in the main article: Relations to other languages and Related languages. Former is a list within the Overview section; latter is an exposition on the influence of C, sitting near the end of the article.

Should we consider these as duplicates, and merge them to one location? Or are we happy with the different emphasis on the somewhat similar content, and leave well alone? Or Perhaps replace the first section with a sentence and keep the latter section? Or something else? Chumpih t 05:29, 26 April 2024 (UTC)[reply]

C is a compiled language

[edit]

A compiled language is "typically" compiled according to Wikipedia. I would like to add "compiled" to describe C. In fact, C is one of the most common languages, if not the most common language, cited as an example of a compiled language. Chris.temp.level.0 (talk) 13:27, 17 July 2024 (UTC)[reply]

@Vincent Lefèvre and Jkudlick: The issue seems to be this edit which inserted "compiled" before "general-purpose programming language" in the lead. Per WP:LEAD, information in the introduction should be a summary of what is in the body of the article and it looks as if one reason given for a revert was doubt about whether the information is in the body. Bear in mind that the lead already refers to "compile" in a couple of places: "C compilers" + "designed to be compiled" + "can be compiled". People like fiddling and Google tells us that C interpreters exist although of course if the term "compiled language" has any meaning, it certainly applies to C. Johnuniq (talk) 01:43, 18 July 2024 (UTC)[reply]
@Johnuniq, Chris.temp.level.0, and Vincent Lefèvre: I was only involved insofar as this article has pending changes protection and I happened to review a pending change that had already been reverted. As I stated on my talk page, I would have accepted the edit if it had not already been reverted. I am glad to see Chris has engaged in discussion here to reach consensus, and I will leave the discussion to those with much better knowledge of this subject than me. — Jkudlick ⚓ (talk) 23:29, 18 July 2024 (UTC)[reply]
@Jkudlick, Johnuniq, and Chris.temp.level.0: I think that "designed to be compiled" already present in the LEDE is sufficient. — Vincent Lefèvre (talk) 12:00, 20 July 2024 (UTC)[reply]
Agree. Chumpih t 14:34, 20 July 2024 (UTC)[reply]