Talk:Struct (C programming language): Difference between revisions

Content deleted Content added
Implementing WP:PIQA (Task 26)
 
(6 intermediate revisions by 5 users not shown)
Line 1:
{{lowercase title}}
{{Talkheader}}
{{WikiProject C++banner shell|class=Start|importance=High}}
{{WikiProject C/C++|importance=High}}
}}
 
== Article or redirect? ==
Line 21 ⟶ 23:
:"''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]]? --[[User:Abdull|Abdull]] ([[User talk:Abdull|talk]]) 22:52, 2 January 2010 (UTC)
:I don't think so. I think it was ''intended'' for uses such as those shown in the example, and not, as ''Type punning'' characterized it{{mdash}}a ''subversion''. See [[#Stuctural padding]] below. &mdash; [[User:Cpiral|<fontspan colorstyle="color:#00C000;">Cp</fontspan><fontspan colorstyle="color:#80C000;">i</fontspan><fontspan colorstyle="color:#C08000;">r</fontspan><fontspan colorstyle="color:#C00000;">al</fontspan>]][[User talk:Cpiral|<fontu colorstyle="color:#2820F0;"><u>Cpiral</u></font>]] 23:16, 1 October 2011 (UTC)
 
== Call by reference or call by value? ==
Line 33 ⟶ 35:
*The internal alignment of data members is not unique to the C struct. There is an analogous dynamic that also "works as expected" concerning subclassing in C++. That said it is very interesting that even if a C compiler is run "unaligned" it will always align (don't say "pad"?) struct members ''inside'' the struct, guaranteeing this manipulation by a sub-struct of quantity N-last elements manipulating its containing struct of N elements.
Salient internals for our lead section are the '''size''' (as mentioned), and the method of '''chaining''' the members of a C struct to one another.
&mdash; [[User:Cpiral|<fontspan colorstyle="color:#00000000000;">Cp</fontspan><fontspan colorstyle="color:#80C000;">i</fontspan><fontspan colorstyle="color:#C08000;">r</fontspan><fontspan colorstyle="color:#C00000;">al</fontspan>]][[User talk:Cpiral|<fontu colorstyle="color:#2820F0;"><u>Cpiral</u></font>]] 21:31, 1 October 2011 (UTC)
 
== Declare/define ==