<!DOCTYPE html>
<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Hello there,</p>
    <p><br>
    </p>
    <p>hope you are all doing well.<br>
    </p>
    <p><br>
    </p>
    <p>While working with libdwarf/dwarfdump,  I noticed the following
      behavior.</p>
    <p>Suppose we have the following code:<br>
    </p>
    <p><br>
      ```C++<br>
      #ifndef CCHANNEL_HPP_<br>
      #define CCHANNEL_HPP_<br>
      <br>
      class CChannel<br>
      {<br>
         public:<br>
          typedef enum<br>
          {<br>
              UNUSED   = 0,<br>
              INACTIVE = 1,<br>
              ACTIVE   = 2,<br>
          } TState;<br>
      <br>
          typedef struct<br>
          {<br>
              TState State;<br>
              int    data;<br>
          } SHK;<br>
      <br>
          CChannel();<br>
          virtual void getData();<br>
          ~CChannel();<br>
      <br>
         private:<br>
          SHK Hk;<br>
      };<br>
      <br>
      #endif /* CCHANNEL_HPP_ */<br>
      ```<br>
      <br>
      It seems that if there is a virtual method inside of a class, the
      DWARF outputs `SHK` struct as an anonymous struct. This means that
      an instantiation of SHK will show a structure with all the info,
      except the name itself("SHK" in this case).<br>
      <br>
      <br>
      Interestingly enough if the struct declaration is  written as the
      following, it does not treat it as a an anonymous struct:<br>
      <br>
      <br>
      ```C++<br>
          typedef struct SHK<br>
          {<br>
              TState State;<br>
              int    data;<br>
          } SHK;<br>
      ```<br>
      <br>
      Assuming this is how it is used:<br>
      ```C++<br>
      #ifndef VC_MSGS_H<br>
      #define VC_MSGS_H<br>
      <br>
      #include "cchannel.hpp"<br>
      #ifdef __cplusplus<br>
      extern "C" {<br>
      #endif<br>
      typedef struct<br>
      {<br>
          int           data;<br>
          CChannel::SHK Channel[1];<br>
      } HkTlm_t;<br>
      <br>
      #ifdef __cplusplus<br>
      }<br>
      #endif<br>
      <br>
      #endif /* VC_MSG_H */<br>
      ```<br>
      <br>
      It also does not happen if `Channel` is just a member instead of
      an array (even if there is a virtual method in CChannel):<br>
      ```C++<br>
      #ifndef VC_MSGS_H<br>
      #define VC_MSGS_H<br>
      <br>
      #include "cchannel.hpp"<br>
      #ifdef __cplusplus<br>
      extern "C" {<br>
      #endif<br>
      typedef struct<br>
      {<br>
          int           data;<br>
          CChannel::SHK Channel;<br>
      } HkTlm_t;<br>
      <br>
      #ifdef __cplusplus<br>
      }<br>
      #endif<br>
      <br>
      #endif /* VC_MSG_H */<br>
      <br>
      ```<br>
    </p>
    <p><br>
    </p>
    <p>I'm just looking for some clarification to make sure I understand
      what is going on here and not going down the wrong path....</p>
    <p>Here is some info about my machine</p>
    <p>gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0<br>
      Copyright (C) 2019 Free Software Foundation, Inc.<br>
      This is free software; see the source for copying conditions. 
      There is NO<br>
      warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
      PURPOSE.<br>
    </p>
    <p>NAME="Pop!_OS"<br>
      VERSION="20.04 LTS"<br>
      ID=pop<br>
      ID_LIKE="ubuntu debian"<br>
      PRETTY_NAME="Pop!_OS 20.04 LTS"<br>
      VERSION_ID="20.04"<br>
      HOME_URL=<a class="moz-txt-link-rfc2396E" href="https://pop.system76.com">"https://pop.system76.com"</a><br>
      SUPPORT_URL=<a class="moz-txt-link-rfc2396E" href="https://support.system76.com">"https://support.system76.com"</a><br>
      BUG_REPORT_URL=<a class="moz-txt-link-rfc2396E" href="https://github.com/pop-os/pop/issues">"https://github.com/pop-os/pop/issues"</a><br>
      PRIVACY_POLICY_URL=<a class="moz-txt-link-rfc2396E" href="https://system76.com/privacy">"https://system76.com/privacy"</a><br>
      VERSION_CODENAME=focal<br>
      UBUNTU_CODENAME=focal<br>
      LOGO=distributor-logo-pop-os</p>
    <p><br>
    </p>
    <p>Hope I was clear enough about my report. I know it's a bit all
      over the place, but my main concern is making sure <i>when</i>/under
      what circumstances will gcc link the variable to the anonymous
      struct  instead of typedef so I can document a tool I work on that
      relies on libdwarf correctly.</p>
    <p><br>
    </p>
    <p>Thanks in advance</p>
    <p>Lorenzo<br>
    </p>
    <p><br>
    </p>
    <p><br>
    </p>
  </body>
</html>