typedef struct { union { u32 slock; struct __raw_tickets { #ifdef __ARMEB__ u16 next; u16 owner; #else u16 owner; u16 next; #endif } tickets; }; } arch_spinlock_t;
Above is a snippet of code from the Linux kernel. What is the purpose of placing the entire structure within the structure. Why not just combine it?
This is a link to the source code.
The Linux kernel is work in progress, not the see-how-it-should-be thing.
I believe that there is no true reason for this, other than the habit of packing everything in structon a higher level. If you thought that “everything is there struct”, you can accidentally lose by adding a new field to the actual unionone and not to structas you expected.
struct
union
, , , - , . , int ( , 1,5), ( , )?
- - .
, , , .
C- , ( ) , , structs , , .
typedef union { int units; float kgs; } amount ; typedef struct { char selling[15]; float unitprice; int unittype; amount howmuch; } product;
Source: https://habr.com/ru/post/1621426/More articles:How to recompile PHP7 using pthreads - pthreadsWhy aren't all threads completed? - pthreadshttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1621423/updating-wordpress-to-use-mysqli-instead-of-mysql&usg=ALkJrhgMcm3Ud9-h8ACsWBhZoK5ba6y7zAКак сообщить Delphi, где он должен разместить свой автоматически созданный код события? - delphiJQuery.on () method is not tied to all elements of Phonegap application on Android 4.0 - jqueryHow to allow user to drag row in vaadin table? - javaresult falls into multiple columns using Algolia and Bootstrap 3 - twitter-bootstrap-3Converting deeply nested json from facebook to dataframe in python - jsonЧто такое тройные знаки равенства и ubuntu2 в Python pip freeze? - pythonget the name of the file downloaded by @PropertySource - javaAll Articles