DPDK patches and discussions
 help / color / mirror / Atom feed
From: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
To: Bruce Richardson <bruce.richardson@intel.com>
Cc: dev@dpdk.org, aconole@redhat.com
Subject: Re: [PATCH] build/eal: add OS defines for C conditional checks
Date: Tue, 14 Dec 2021 01:58:03 +0300	[thread overview]
Message-ID: <20211214015803.763d30d1@sovereign> (raw)
In-Reply-To: <20211210145330.108256-1-bruce.richardson@intel.com>

2021-12-10 14:53 (UTC+0000), Bruce Richardson:
[...]

Acked-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
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``.

  parent reply	other threads:[~2021-12-13 22:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-10 14:53 Bruce Richardson
2021-12-13  7:21 ` Jerin Jacob
2021-12-13 22:58 ` Dmitry Kozlyuk [this message]
2021-12-14 12:03   ` Bruce Richardson
2021-12-16 15:21 ` [PATCH v2] " Bruce Richardson
2022-01-17 18:20   ` Thomas Monjalon

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=20211214015803.763d30d1@sovereign \
    --to=dmitry.kozliuk@gmail.com \
    --cc=aconole@redhat.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.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 NNTP newsgroup(s).