0

Some gcc options have multiple representations.

For example, --warn-unused-macros can get the same result as -Wunused-macros.

But I checked the gcc website 3.8 Options to Request or Suppress Warnings.

There is only a description of -Wunused-macros.

How does gcc lead the two options to the same result?

Thank you !!!

Gerhard
  • 6,850
  • 8
  • 51
  • 81
alan
  • 1
  • 2
  • 2
    `How gcc confirms` What do you mean by "confirms"? `How does gcc lead the two options to the same result?` What do you mean by "how"? Why not just assume that `gcc` just checks `if (option == "--warn-unused-macros" || option == "-Wunused-macros") warn_about_unused_macros()`? – KamilCuk Sep 20 '21 at 10:51

1 Answers1

1

For example, --warn-unused-macros can get the same result as -Wunused-macros.

Mmh, indeed it appears to be an undocumented alternative way to specify -W... parameters (it is not even reported by gcc --help=warnings). However I only did a quick search, so it may be documented somewhere (maybe someone else may point to the documentation if they found it).

Also, if I execute gcc --warn-long-long2, GCC will correctly tell me that I may have misspelled the --warn-long-long option (a.k.a. -Wlong-long). So, suggestions correctly work for this alternate naming.


How does gcc lead the two options to the same result?

The two options lead to the same result simply because GCC treats them as the same option with different names. Many softwares have several names for the same option. I'm not sure what your doubt/question is about this.

Do you want to know specifically how GCC parse command line options internally?

Luca Polito
  • 2,387
  • 14
  • 20
  • Yes, I want to know specifically how GCC parse command line options internally? Thank you very much for your help! – alan Sep 20 '21 at 11:03
  • @alan From the [GCC official repository](https://gcc.gnu.org/git/?p=gcc.git;a=summary), it appears that GCC uses custom functions to parse command line options, but I'm not 100% sure. However, GCC codebase is complex; if you want some examples of how C applications parse command line options, take a look at this [SO question](https://stackoverflow.com/questions/9642732/parsing-command-line-arguments-in-c). – Luca Polito Sep 20 '21 at 11:16