From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 99BC843437; Tue, 5 Dec 2023 02:22:25 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1FECA40299; Tue, 5 Dec 2023 02:22:25 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id BA2A540291 for ; Tue, 5 Dec 2023 02:22:23 +0100 (CET) Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SkjRq22F3zvQth; Tue, 5 Dec 2023 09:21:43 +0800 (CST) Received: from [10.67.121.161] (10.67.121.161) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 5 Dec 2023 09:22:20 +0800 Subject: Re: [RFC v2 1/6] argparse: add argparse library To: Stephen Hemminger CC: , , , References: <20231121122651.7078-1-fengchengwen@huawei.com> <20231204075048.894-1-fengchengwen@huawei.com> <20231204075048.894-2-fengchengwen@huawei.com> <20231204091012.7aa5046c@hermes.local> From: fengchengwen Message-ID: Date: Tue, 5 Dec 2023 09:22:20 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: <20231204091012.7aa5046c@hermes.local> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.121.161] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpeml500024.china.huawei.com (7.185.36.10) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Hi Stephen, On 2023/12/5 1:10, Stephen Hemminger wrote: > On Mon, 4 Dec 2023 07:50:43 +0000 > Chengwen Feng wrote: > >> + static struct rte_argparse obj = { >> + .prog_name = "test-demo", >> + .usage = "[EAL options] -- [optional parameters] [positional parameters]", >> + .descriptor = NULL, >> + .epilog = NULL, >> + .exit_on_error = true, >> + .callback = argparse_user_callback, >> + .args = { >> + { "--aaa", "-a", "aaa argument", (void *)&aaa_val, (void *)100, RTE_ARGPARSE_ARG_NO_VALUE | RTE_ARGPARSE_ARG_VALUE_INT }, >> + { "--bbb", "-b", "bbb argument", (void *)&bbb_val, NULL, RTE_ARGPARSE_ARG_REQUIRED_VALUE | RTE_ARGPARSE_ARG_VALUE_INT }, >> + { "--ccc", "-c", "ccc argument", (void *)&ccc_val, (void *)200, RTE_ARGPARSE_ARG_OPTIONAL_VALUE | RTE_ARGPARSE_ARG_VALUE_INT }, >> + { "--ddd", "-d", "ddd argument", NULL, (void *)1, RTE_ARGPARSE_ARG_NO_VALUE }, >> + { "--eee", "-e", "eee argument", NULL, (void *)2, RTE_ARGPARSE_ARG_REQUIRED_VALUE }, >> + { "--fff", "-f", "fff argument", NULL, (void *)3, RTE_ARGPARSE_ARG_OPTIONAL_VALUE }, >> + { "ooo", NULL, "ooo argument", (void *)&ooo_val, NULL, RTE_ARGPARSE_ARG_REQUIRED_VALUE | RTE_ARGPARSE_ARG_VALUE_INT }, >> + { "ppp", NULL, "ppp argument", NULL, (void *)300, RTE_ARGPARSE_ARG_REQUIRED_VALUE }, >> + }, >> + }; >> + > > Could the API be made to work with immutable initializers? > I.e allowing the application to use: > static const struct rte_argparse_obj { Current impl, it can't be immutable, because the API will modify some reserved bit in args.flags field. > > Also better to just skip the NULL elements here, and use field initializers for the args. Yes, both are OK. > That way when structure layout changes, the example will still work. > Also, pointers do not have to be cast to void * in C code. OK, will modify in v3. Thanks > . >