Does mbutils.c really need to use L'\0' ?

Started by Tom Laneover 15 years ago5 messages
#1Tom Lane
tgl@sss.pgh.pa.us

I grow weary of mopping up after pgindent, as in
http://archives.postgresql.org/pgsql-committers/2010-07/msg00069.php

The problem evidently is that pgindent hasn't heard of wide character
constants. No doubt the best fix would be to teach it about them;
but given that we seem to have next to no use for such constants,
I'm dubious that it's worth the trouble. I suggest that it might be
best to replace these usages of L'\0' by plain scalar 0. Does anyone
think that wouldn't work or is too grotty?

regards, tom lane

#2Andrew Dunstan
andrew@dunslane.net
In reply to: Tom Lane (#1)
Re: Does mbutils.c really need to use L'\0' ?

Tom Lane wrote:

I grow weary of mopping up after pgindent, as in
http://archives.postgresql.org/pgsql-committers/2010-07/msg00069.php

The problem evidently is that pgindent hasn't heard of wide character
constants. No doubt the best fix would be to teach it about them;
but given that we seem to have next to no use for such constants,
I'm dubious that it's worth the trouble. I suggest that it might be
best to replace these usages of L'\0' by plain scalar 0. Does anyone
think that wouldn't work or is too grotty?

or maybe 0x0000, which I gather from
<http://en.wikipedia.org/wiki/Wide_character&gt; is the usual locution.

cheers

andrew.

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andrew Dunstan (#2)
Re: Does mbutils.c really need to use L'\0' ?

Andrew Dunstan <andrew@dunslane.net> writes:

Tom Lane wrote:

I'm dubious that it's worth the trouble. I suggest that it might be
best to replace these usages of L'\0' by plain scalar 0. Does anyone
think that wouldn't work or is too grotty?

or maybe 0x0000, which I gather from
<http://en.wikipedia.org/wiki/Wide_character&gt; is the usual locution.

Hm. I don't really read that page as suggesting that 0x0000 is what to
use if your compiler hasn't got wide chars. I'd tend to go with just 0,
which is a reasonably common substitute for non-wide '\0' ...

regards, tom lane

#4Takahiro Itagaki
itagaki.takahiro@oss.ntt.co.jp
In reply to: Tom Lane (#3)
Re: Does mbutils.c really need to use L'\0' ?

Tom Lane <tgl@sss.pgh.pa.us> wrote:

I'm dubious that it's worth the trouble. I suggest that it might be
best to replace these usages of L'\0' by plain scalar 0.

I'd tend to go with just 0,
which is a reasonably common substitute for non-wide '\0' ...

I think all of the following codes work in the same way
at least on Windows, where the codes are actually used.

utf16[dstlen] = L'\0';
utf16[dstlen] = '\0';
utf16[dstlen] = 0;
utf16[dstlen] = (WCHAR) 0;

Regards,
---
Takahiro Itagaki
NTT Open Source Software Center

#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: Takahiro Itagaki (#4)
Re: Does mbutils.c really need to use L'\0' ?

Takahiro Itagaki <itagaki.takahiro@oss.ntt.co.jp> writes:

I think all of the following codes work in the same way
at least on Windows, where the codes are actually used.

utf16[dstlen] = L'\0';
utf16[dstlen] = '\0';
utf16[dstlen] = 0;
utf16[dstlen] = (WCHAR) 0;

The last one seems like the best choice, since it makes the intent visible.
Committed that way --- thanks for the suggestion!

regards, tom lane