https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83161

            Bug ID: 83161
           Summary: Feature request: add a builtin for printing structs
                    and classes
           Product: gcc
           Version: 7.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: other
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Hi-Angel at yandex dot ru
  Target Milestone: ---

It's very useful for debugging to pretty-print an entire struct. Typically
people firing up gdb for this, but sometimes it's hard, like on embedded
systems; and always is time-consuming.

This issue is popular enough that e.g. the new systems language Rust have this
functionality built-in.

Some relevant questions to show demand:
1. "Printing values of all fields in a C++ structure"
https://stackoverflow.com/questions/2758937/printing-values-of-all-fields-in-a-c-structure
22k views.
2. Someone attempting the same thing for linux kernel
https://stackoverflow.com/questions/14572015/how-to-print-to-screen-a-struct-and-all-its-content
4k views.

Prior art: Haskell language have a very simple implementation: adding after
declaration of a type "derive Show" generates a code for returning a string
with human-readable description of its object. And if a programmer wants to
tweak representation of a specific type, they override "show" function.

So, I imagine a function "_gcc_show()", and 2 attributes — one to generate a
code for a struct/class, another to override a "_gcc_show()" for certain type —
would be more than enough.

Reply via email to