On Tue, Aug 19, 2025 at 10:48:27PM +0200, Walter Alejandro Iglesias wrote:
> Hello Ingo,
> 
> On Tue, Aug 19, 2025 at 05:39:13PM +0200, Ingo Schwarze wrote:
> > Hi Walter,
> > 
> > Walter Alejandro Iglesias wrote on Mon, Aug 18, 2025 at 06:40:04PM +0200:
> > 
> > > Question for the experts.  Let's take the following example:
> > > 
> > > ----->8------------->8--------------------
> > > #include <stdio.h>
> > > #include <string.h>
> > > #include <wchar.h>
> > > 
> > > #define period            0x2e
> > > #define question  0x3f
> > > #define exclam            0x21
> > > #define ellipsis  L'\u2026'
> > > 
> > > const wchar_t p[] = { period, question, exclam, ellipsis };
> > 
> > In addition to what otto@ said, this is bad style for more than one
> > reason.
> > 
> > First of all, that data type of the constant "0x2e" is "int",
> > see for example C11 6.4.4.1 (Integer constants).  Casting "int"
> > to "wchar_t" doesn't really make sense.  On OpenBSD, it only
> > works because UTF-8 is the only supported character encoding *and*
> > wchar_t stores Unicode codepoints.  But neither of these choices
> > are portable.  What you want is (C11 6.4.4.4 Character constants):
> > 
> >   #define period    L'.'
> >   #define question  L'?'
> >   #define exclam    L'!'

As I made this change to my code (https://en.roquesor.com/fmtroff.html)
the following reminded me why, at some point, I decided to switch to
hexadecimal notation.

  #define backslash     L'\\'
  #define apostrophe    L'\''

It isn't very confusing there, but among the arguments of a function or
a conditional...


-- 
Walter

Reply via email to