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 8A647A034F; Mon, 13 Dec 2021 23:58:07 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1C8E3406A2; Mon, 13 Dec 2021 23:58:07 +0100 (CET) Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) by mails.dpdk.org (Postfix) with ESMTP id 6B5A240042 for ; Mon, 13 Dec 2021 23:58:05 +0100 (CET) Received: by mail-lj1-f178.google.com with SMTP id z8so25838463ljz.9 for ; Mon, 13 Dec 2021 14:58:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=O3P3HHVgnbNW/l17IDYjigAEfbZdl4hPJHSBsUtbRzI=; b=LfJmx8kHx0gLqTJPSKo2jPO6rWrDbtqk3/yy/MbbVmglgPwVbMeWIrY4DSPOMFuz1f UMUPLpa6JzGDK6oCeTbIGMu0dhUdPU3K/tGV58hBHOZ1tG+ULhdzB5gs4N8G1RoGqOQi 7rWd9BArn6fXNYsB2LTWBQjfGoW088aHz3GPQfuWGrtQaejPEyB0IiETEqq5kp1oSwzh azH1PzKIddoIWs244aa5HXF1C7QZIrR5ZBVILTLQbaj7JdXjHQm9p23qqd6sOCBXqyM1 nnCaH5dt1LxcbqT9QqnxbR01mQF5goe/GrUa29UyHXZjLqN5dUsyRg8VZUWCEnV3I49+ LtHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=O3P3HHVgnbNW/l17IDYjigAEfbZdl4hPJHSBsUtbRzI=; b=5je/AXVknoQJ0P4Eb++heH6sgXTthjMRnlAisPgz9ddWs7/vi9SwaRrHFx81KCttMy 9egFGHxIJ4fguKtpd33Qp8wLiCDxZg23Q43BRtglAoZSbWnGj5EQ5VFLnWvyE67jyjjt kBmwBUk+vXms2wwmlv9hGb5eg+rm6QSAdaWp/eNHf6ZKVU6cctMJRSCYrphMV26sLEC/ lnyaIGV0ojc+c80Y3kqiQr4aTt2rR/xYmrXf+wT3hYqVw/G3voL4C907FMv1hAZLIMA0 YkDUlQK/hjZ25p6J/xNgJHB5j44zjQldli98wVgCoPzaemwa+C0wYt9AuWbS2gJvOsRv ellg== X-Gm-Message-State: AOAM530LWO3TD7Q1vHAzyEjG7virFM83zoTstDzoql/UpcnyM1vTu4XH AxgNSOlGW5XlCajFf72H0Ks= X-Google-Smtp-Source: ABdhPJzeGzBrPZJ5krABv12BB+JzefPwreSEXhylJh5WzKPndZiiuN/UyzIUJRr9ZLQWc47TkSyLSQ== X-Received: by 2002:a2e:3c17:: with SMTP id j23mr1346959lja.391.1639436284878; Mon, 13 Dec 2021 14:58:04 -0800 (PST) Received: from sovereign (broadband-37-110-65-23.ip.moscow.rt.ru. [37.110.65.23]) by smtp.gmail.com with ESMTPSA id q15sm1600519lfp.32.2021.12.13.14.58.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Dec 2021 14:58:04 -0800 (PST) Date: Tue, 14 Dec 2021 01:58:03 +0300 From: Dmitry Kozlyuk To: Bruce Richardson Cc: dev@dpdk.org, aconole@redhat.com Subject: Re: [PATCH] build/eal: add OS defines for C conditional checks Message-ID: <20211214015803.763d30d1@sovereign> In-Reply-To: <20211210145330.108256-1-bruce.richardson@intel.com> References: <20211210145330.108256-1-bruce.richardson@intel.com> X-Mailer: Claws Mail 3.18.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 2021-12-10 14:53 (UTC+0000), Bruce Richardson: [...] Acked-by: Dmitry Kozlyuk with one typo below and some considerations for the future in the bottom. > +Defines to Avoid Conditional Compilation > +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > + > +In many cases in DPDK, one wants to optionally compile code based on the target platform, > +or runtime environment. "Compile" -> "run", that's the point to use conditionals instead of macros. > +While this can be done using the conditional compilation directives, > +e.g. ``#ifdef RTE_EXEC_ENV_LINUX``, present in DPDK for many releases, > +this can also be done in many cases using regular ``if`` statements and the following defines: > + > +* ``RTE_ENV_FREEBSD``, ``RTE_ENV_LINUX``, ``RTE_ENV_WINDOWS`` - these define ids for each operating system environment. > +* ``RTE_EXEC_ENV`` - this defines the id of the current environment, i.e. one of the items in list above. > +* ``RTE_EXEC_ENV_IS_FREEBSD``, ``RTE_EXEC_ENV_IS_LINUX``, ``RTE_EXEC_ENV_IS_WINDOWS`` - 0/1 values indicating if the current environment is that specified, > + shortcuts for checking e.g. ``RTE_EXEC_ENV == RTE_ENV_WINDOWS`` [...] I wonder whether #if RTE_EXEC_ENV_IS_xxx should be preferred over #ifdef RTE_EXEC_ENV_xxx, so that all checks use the same symbol (and then remove old macros one day). Since C conditionals are preferred over #ifdef, I suggest to give pointers when to use one or another mechanism: If a code fragment can compile on all platforms, but cannot run on some due to lack of support, branch on constants. If a code fragment cannot compile on all platforms (e.g. use of OS-specific headers or macros), but constitutes only a small fraction of the file, use conditional compilation. If a group of functions implement an interface in an OS- or platform-specific way, create a file for each of the supported environments and plug an appropriate file from ``meson.build``.