Re: strange structs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



so usp <so_usp@yahoo.com.br> writes:

>> > static struct name1 name2 = {
>> >    .some_struct = some_function,
>> >    .some_struct = some_function,
>> >
>> > ...
>> > };
>> 
>> 'name2' is the variable name.
>> 'struct name1' is the type.
>> The field 'some_struct' is initialized to
>> 'some_function'.
>
> Is this inicialization done at the system
> initialization?
> So, can I export 'some_struct' to my code and use it
> without initializing anything? 
> And would I have to use these fields like:
> 'name2.some_struct' ?

It's just a new (C99 standard) syntax for struct initialization.  The
initialization is the same as with older syntaxes.  

I'm not going to double check the standard to make sure, but I think
in the example below, struct a will always be initialized in the same
way as struct b, and struct c in the same way as d.  Someone please
correct me if I'm wrong.

  struct so_usp {
    int n;
    int m;
  };
  
  struct so_usp a = { 2, 3, };
  struct so_usp b = {
    .n = 2,
    .m = 3,
  };
  
  int main(void)
  {
      struct so_usp c = { 2, 3, };
      struct so_usp d = {
        .n = 2,
        .m = 3,
      };
  
      return 0;
  }
    

-- 
  Ed L Cashin <ecashin@coraid.com>


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux