Content deleted Content added
m Archiving 1 discussion(s) from Talk:C (programming language)) (bot |
m Archiving 1 discussion(s) from Talk:C (programming language)) (bot |
||
Line 204:
: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)
== "Only the last member stored is valid" ==
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."
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.
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.
The following is pulled directly from the C17 standard. It lies in a footnote under section 6.5.2.3.3:
"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)
|