public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Jiří Wolker" <woljiri@gmail.com>
To: gcc@gcc.gnu.org
Subject: Feature request: Warning when .c file gets #include'd
Date: Fri, 02 Dec 2022 15:57:44 +0100	[thread overview]
Message-ID: <87359xyhsn.fsf@gmail.com> (raw)


Hi,

I've met a guy that is learning C and got stuck when the linker produced
a screenful of messages about that he did something define multiple
times. The cause of the problem was trivial:

    He did ``#include "something.c"'' in his code.

In the past, I also did this thing multiple times and I would appreciate
a warning produced by the gcc when compiling C/C++ file that includes a
file ending in .c, .cx, .cpp or .cxx.

What do you think about that?

I would prefer to make this enabled when -Wextra is used.

Based on my past experience with using .c files in the include
directive, I can think of these problems.

  - Sometimes, I want to include a file that is definitely not a header,
    but also it is not a stand-alone source file. I personally prefer
    using .inc suffix, but some people possibly terminate the file names
    with .c suffix like a source file.

    Example:  list of enum fields included from a separate file that was
              generated by a script

  - In some projects, someone can deliberately want to include another
    source file. For example, this can happen when doing unit tests and
    you do not want to specify the source file name on the command line.

If you accept that, I can try to implement that. (That would be my first
contribution to this project and I do not know gcc codebase, but it
looks like a relatively simple change.) Do you think that it would need
a copyright assignment?

Thanks,
Jiří

             reply	other threads:[~2022-12-02 14:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-02 14:57 Jiří Wolker [this message]
2022-12-02 15:46 ` Marek Polacek
2022-12-02 16:13   ` Jonathan Wakely

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87359xyhsn.fsf@gmail.com \
    --to=woljiri@gmail.com \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).