[ntp:hackers] Replacement of hardcoded file paths.
davehart at gmail.com
Fri Jul 29 02:26:19 UTC 2011
On Thu, Jul 28, 2011 at 21:52 UTC, Brian Utterback
<brian.utterback at oracle.com> wrote:
> The usual way to do this is to use the pre-processor "#" operator, which
> automatically places quotes around the argument. You need to use two
> levels of expansion to make sure the argument expands properly:
> #define XSTR(a) #a
> #define STR(a) XSTR(a)
> #define NTP_VAR /var/NTP
> char statsdir[MAXFILENAME] = STR(NTP_VAR)
Sounds good to me, though I might prefer QUOTE(NTP_VAR) to STR(NTP_VAR).
> The question I have is, does anybody know any reason not to do this,
> like do we support a compiler that does not support this idiom? Or, does
> anybody know a better way to accomplish this?
4.2.4 was the last version of the NTP distribution that supported K&R
C compilers. Now, ANSI C (or ISO C or c89 or c90, all the same thing)
is a requirement to build NTP. The preprocessor "stringizing" #
operator is required by that C standard.
More information about the hackers