0
    struct hpet : public description_table_header
{
    uint8_t hardware_rev_id;
    uint8_t comparator_count:5;
    uint8_t counter_size:1;
    uint8_t reserved:1;
    uint8_t legacy_replacement:1;
    pci_vendor_t pci_vendor_id;
    address_structure address;
    uint8_t hpet_number;
    uint16_t minimum_tick;
    uint8_t page_protection;
} __attribute__((packed));

Why is there a public after the struct name and also __attribute__((packed)), why is packed inside paranthesis???
This is a table for a HPET(High Precision Event Timer).

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
memnonila
  • 359
  • 2
  • 12

2 Answers2

2

In C++, a colon : followed by optional public/private/protected designator and a type name is the syntax for specifying inheritance.

In your code, the hpet class inherits the description_table_header class.

See this answer for a discussion of the differences between public, private, and protected inheritance.

Community
  • 1
  • 1
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
  • 1
    this is C++ (which is an excellent language for low level code) You struct is publically inheriting (which struct can do - the same way classes do) – RichardPlunkett Dec 29 '13 at 14:09
2

The code is C++ and not C as you tagged it. That's quite an important detail.

The public here is the access specifier for the inheritance (the struct inherits from description_table_header). This will be covered in all good C++ textbooks. A relevant question here on SO is: Difference between private, public, and protected inheritance. The specification of public for a struct is not actually needed since, for a struct, that is the default.

The __attribute__((packed)) is a compiler specific extension that specifies the layout of the struct. In this case the struct is packed so that there is no padding in the struct.

Community
  • 1
  • 1
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490