From: Jakub Jelinek <jakub@redhat.com>
To: Tom de Vries <tdevries@suse.de>
Cc: dwz@sourceware.org, mark@klomp.org
Subject: Re: [committed] Make main more readable
Date: Wed, 17 Mar 2021 18:28:18 +0100 [thread overview]
Message-ID: <20210317172818.GI231854@tucnak> (raw)
In-Reply-To: <a3c41263-1c47-5b28-33a1-6281b2ac75db@suse.de>
On Wed, Mar 17, 2021 at 02:37:57PM +0100, Tom de Vries wrote:
> On 3/17/21 2:18 PM, Jakub Jelinek wrote:
> > On Wed, Mar 17, 2021 at 02:14:45PM +0100, Tom de Vries wrote:
> >> @@ -17048,10 +17050,12 @@ main (int argc, char *argv[])
> >> outfile = NULL;
> >> hardlink = false;
> >> parse_args (argc, argv, &hardlink, &outfile);
> >> + nr_files = argc - optind;
> >> + files = (const char **)&argv[optind];
> >>
> >> - if (optind == argc || optind + 1 == argc)
> >> + if (nr_files <= 1)
> >> {
> >> - const char *file = optind == argc ? "a.out" : argv[optind];
> >> + const char *file = nr_files == 0 ? "a.out" : files[0];
> >
> > Isn't that aliasing violation?
>
> Sorry, I don't see it, can you be specific about which entity is
> accessed with an incompatible type?
char * and const char * are different types from C aliasing POV I think.
Now, as these are arguments of main and argv can be const char **
or char ** interchangeably, what is the dynamic type is a little bit fuzzy,
but I'd say mixing accesses to argv array elements, accessing some of them
through char * effective type (e.g. in getopt_long) and others through
const char * effective type is problematic.
Making files char ** and then casting if needed (say (const char *)(files[0]))
is fine of course.
Jakub
next prev parent reply other threads:[~2021-03-17 17:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-17 13:14 Tom de Vries
2021-03-17 13:18 ` Jakub Jelinek
2021-03-17 13:37 ` Tom de Vries
2021-03-17 17:28 ` Jakub Jelinek [this message]
2021-03-18 10:30 ` Tom de Vries
2021-03-18 18:52 ` Florian Weimer
2021-03-19 16:43 ` [committed] Change files var in main to char ** Tom de Vries
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=20210317172818.GI231854@tucnak \
--to=jakub@redhat.com \
--cc=dwz@sourceware.org \
--cc=mark@klomp.org \
--cc=tdevries@suse.de \
/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).