[Nut-upsdev] Default NUT PORT

Arjen de Korte nut+devel at de-korte.org
Sun Jan 14 10:48:49 CET 2007


> Keep in mind that PORT can be changed at ./configure time
> (--with-port), so hardcoding it is not an option.

That's why I warned about this. :-)

> There is a way for the proprocessor to convert a number to a string.
> The syntax is a bit obscure, and I have never seen it used in any
> actual program.

You will, later today... ;-)

> It works like this:
>
>  #define PORT 3493
>  #define string_const_aux(x) #x
>  #define string_const(x) string_const_aux(x)
>
>  char *s = string_const(PORT);
>
> Running this through the preprocessor (gcc -E), you get
>
>  char *s = "3493";
>
> The indirection is needed by the way. If you just do
> string_const_aux(PORT), you get "PORT" and not "3493". I hope you
> agree that this is obscure.

It is, but if it works and is portable, I don't mind.

> I think a better solution is to just #define PORT as a character
> string in the first place. As far as I can see, this primarily affects
> two lines: include/config.h:197 (i.e. configure.in:505) and
> clients/upsclient.c:966.

That might be an option later on. But since that requires a change of the
upsclient interface, that was not my first thought.

Best regards, Arjen





More information about the Nut-upsdev mailing list