Talk:Struct (C programming language)
![]() | C/C++ Start‑class Mid‑importance | |||||||||
|
Article or redirect?
From history, this page has been in three rather different states:
- An independent article (which I just restored)
- A redirect to Record (computer science) (previous state)
- A redirect to Object composition
Each is reasonable (although the last perhaps less so), but there seems to have been no discussion of the matter. Worse, the Structs page had gotten set as redirecting to Object composition, making the singular and plural of "struct" refer to very different things.
The evolution seems to be that what started out as being about C (programming language) specifically got geared towards C++, and then towards abstract object orientation. Later someone reacted to this and changed the redirect to the more common (but still abstract) interpretation of Record (computer science). 90.230.192.94 (talk) 17:17, 8 May 2009 (UTC)
Separate name spaces, and recommended style
This article should observe that struct names are a namespace separate from the main namespace of types and variables, so that one can declare
typedef struct ListNode { int val; struct ListNode *next; } ListNode;
That is, it is not necessary to use different names (ListNode_ and ListNode) for the two C views of wha is essentially the same data type.
All the best, --Jorge Stolfi (talk) 21:57, 15 May 2009 (UTC)
Type punning
- "For example, common Internet protocols rely on the fact that C compilers insert padding between struct fields in predictable ways [...]"
Is this an example of type punning? --Abdull (talk) 22:52, 2 January 2010 (UTC)
Call by reference or call by value?
In C, when calling a subroutine or receiving a return value, is a struct passed/returned by value or by reference? Does the ISO/IEC C standard discuss this topic explicitly? Thanks, --Abdull (talk) 09:18, 2 May 2010 (UTC)
- I haven't looked at the standard you mention, but it has always been part of C that a struct is passed and returned by value. If a struct contains data occupying 1000 bytes, the compiler pushes 1000 bytes onto the stack. C programmers often pass a pointer to a struct, which is what a "pass by reference" language would do. I suppose this could be mentioned somewhere (it is implied at C (programming language)#Characteristics), but it's probably excessive detail for an article. Johnuniq (talk) 02:03, 3 May 2010 (UTC)
Structural padding
The lead section is unclear where it talks about the interesting subject of the internals of structs. It says there is padding stored between the members. This needs to be clarified. There is an attempt to explain this padding by using subtyping. But the sole explanation, that is the example code in the lead paragraph, tries to relate padding to subtyping in a way that is not clear: manipulating a compound type composed of N members via a subtype similarly composed, but of only N-x members, relies on superposition, not on some fuzzy notion of padding. (There is an analogous dynamic that also "works as expected" concerning subclassing in C++. Does this help this discussion?) — CpiralCpiral 17:31, 1 October 2011 (UTC)