[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c

locale and wchar_t character constant

Owner

2/10/2011 12:22:00 PM

what's wrong with this code?

#include <locale.h>
#include <stdio.h>
#include <wchar.h>

main(){
setlocale(LC_CTYPE, "");
wchar_t a = L'CN';
putwchar(a);

}

result

test.c:7: warning: multi-character character constant
10 Answers

Ben Bacarisse

2/10/2011 1:01:00 PM

0

Owner <Owner@Owner-PC.com> writes:

> what's wrong with this code?
>
> #include <locale.h>
> #include <stdio.h>
> #include <wchar.h>
>
> main(){
int main(void)

> setlocale(LC_CTYPE, "");
> wchar_t a = L'í??';
> putwchar(a);
>
> }
>
> result
>
> test.c:7: warning: multi-character character constant

It works for me (as I'd expect). I image that the particular multi-byte
sequence you have is not being recognised by the compiler.

--
Ben.

Owner

2/10/2011 1:40:00 PM

0

On Thu, 10 Feb 2011 13:01:02 +0000, Ben Bacarisse wrote:

> Owner <Owner@Owner-PC.com> writes:
>
>> what's wrong with this code?
>>
>> #include <locale.h>
>> #include <stdio.h>
>> #include <wchar.h>
>>
>> main(){
> int main(void)
>
>> setlocale(LC_CTYPE, "");
>> wchar_t a = L'CN';
>> putwchar(a);
>>
>> }
>>
>> result
>>
>> test.c:7: warning: multi-character character constant
>
> It works for me (as I'd expect). I image that the particular multi-byte
> sequence you have is not being recognised by the compiler.

So you mean I should switch my tcc compiler to better compiler?

Keith Thompson

2/10/2011 4:50:00 PM

0

Owner <Owner@Owner-PC.com> writes:
> what's wrong with this code?
>
> #include <locale.h>
> #include <stdio.h>
> #include <wchar.h>
>
> main(){

Should be "int main(void) {", but that's not the problem.

> setlocale(LC_CTYPE, "");
> wchar_t a = L'í??';
> putwchar(a);
>
> }
>
> result
>
> test.c:7: warning: multi-character character constant

It's hard to tell. Your article appears to have an euc-kr encoding
(judging by the "Content-Type:" header on your article), but
that could have been introduced by some news software somewhere.
Is your original source file encoded in euc-kr?

Probably your compiler doesn't recognize the character encoding you
used in your source file, and is interpreting the bytes between the
single quotes as two 8-bit characters, producing a multi-character
character constant.

Note that a call to setlocale() (which occurs at run time) cannot
affect the compiler's interpretation of source characters.

See what your compiler's documentation says about source character
sets. You might hae better luck using UTF-8.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.ne...
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Ben Bacarisse

2/10/2011 6:19:00 PM

0

Owner <Owner@Owner-PC.com> writes:

> On Thu, 10 Feb 2011 13:01:02 +0000, Ben Bacarisse wrote:
>> Owner <Owner@Owner-PC.com> writes:
<snip>
>>> #include <locale.h>
>>> #include <stdio.h>
>>> #include <wchar.h>
>>>
>>> main(){
>> int main(void)
>>> setlocale(LC_CTYPE, "");
>>> wchar_t a = L'í??';
>>> putwchar(a);
>>> }
>>>
>>> result
>>>
>>> test.c:7: warning: multi-character character constant
>>
>> It works for me (as I'd expect). I image that the particular multi-byte
>> sequence you have is not being recognised by the compiler.
>
> So you mean I should switch my tcc compiler to better compiler?

Not necessarily. There may be compiler options that will make it work
or, as Keith has suggested, you may be using an encoding that is not
recognised by tcc. It might even as a simple as setting an environment
variable during the compile.

However, tcc is a small project and multi-byte support may well have
been something that's been left to one side. There is a good mailing
tcc list: tinycc-devel@nongnu.org.

--
Ben.

Owner

2/10/2011 9:07:00 PM

0

On Thu, 10 Feb 2011 08:50:10 -0800, Keith Thompson wrote:

> Owner <Owner@Owner-PC.com> writes:
>> what's wrong with this code?
>>
>> #include <locale.h>
>> #include <stdio.h>
>> #include <wchar.h>
>>
>> main(){
>
> Should be "int main(void) {", but that's not the problem.
>
>> setlocale(LC_CTYPE, "");
>> wchar_t a = L'CN';
>> putwchar(a);
>>
>> }
>>
>> result
>>
>> test.c:7: warning: multi-character character constant
>
> It's hard to tell. Your article appears to have an euc-kr encoding
> (judging by the "Content-Type:" header on your article), but
> that could have been introduced by some news software somewhere.
> Is your original source file encoded in euc-kr?

yes, korean locale
>
> Probably your compiler doesn't recognize the character encoding you
> used in your source file, and is interpreting the bytes between the
> single quotes as two 8-bit characters, producing a multi-character
> character constant.
>
> Note that a call to setlocale() (which occurs at run time) cannot
> affect the compiler's interpretation of source characters.
>
> See what your compiler's documentation says about source character
> sets. You might hae better luck using UTF-8.



Owner

2/10/2011 11:43:00 PM

0

On Thu, 10 Feb 2011 07:21:54 -0500, Owner wrote:

> what's wrong with this code?
>
> #include <locale.h>
> #include <stdio.h>
> #include <wchar.h>
>
> main(){
> setlocale(LC_CTYPE, "");
> wchar_t a = L'CN';
> putwchar(a);
>
> }
>
> result
>
> test.c:7: warning: multi-character character constant

Strangely this below code works then.

#include <locale.h>
#include <stdio.h>
#include <wchar.h>


main(){
wchar_t *a = L"CN±U";
setlocale(LC_ALL, "ko");

wprintf(L"%s",a);

}

Keith Thompson

2/10/2011 11:53:00 PM

0

Owner <Owner@Owner-PC.com> writes:
> On Thu, 10 Feb 2011 07:21:54 -0500, Owner wrote:
>> what's wrong with this code?
>>
>> #include <locale.h>
>> #include <stdio.h>
>> #include <wchar.h>
>>
>> main(){
>> setlocale(LC_CTYPE, "");
>> wchar_t a = L'í??';
>> putwchar(a);
>>
>> }
>>
>> result
>>
>> test.c:7: warning: multi-character character constant
>
> Strangely this below code works then.
>
> #include <locale.h>
> #include <stdio.h>
> #include <wchar.h>
>
>
> main(){
> wchar_t *a = L"í??ê¸?";
> setlocale(LC_ALL, "ko");
>
> wprintf(L"%s",a);
>
> }

Well, at least the compiler isn't going to warn about the second
case; you're using a string literal rather than a character constant,
so you can have as many characters/bytes/glyphs between them as
you like.

What does wcslen(a) return?

(Note that, in my newsreader, your string literal looks something like
L"[][]"
only fuzzier.)

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.ne...
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Owner

2/11/2011 12:38:00 AM

0

On Thu, 10 Feb 2011 15:52:49 -0800, Keith Thompson wrote:

> Owner <Owner@Owner-PC.com> writes:
>> On Thu, 10 Feb 2011 07:21:54 -0500, Owner wrote:
>>> what's wrong with this code?
>>>
>>> #include <locale.h>
>>> #include <stdio.h>
>>> #include <wchar.h>
>>>
>>> main(){
>>> setlocale(LC_CTYPE, "");
>>> wchar_t a = L'CN';
>>> putwchar(a);
>>>
>>> }
>>>
>>> result
>>>
>>> test.c:7: warning: multi-character character constant
>>
>> Strangely this below code works then.
>>
>> #include <locale.h>
>> #include <stdio.h>
>> #include <wchar.h>
>>
>>
>> main(){
>> wchar_t *a = L"CN±U";
>> setlocale(LC_ALL, "ko");
>>
>> wprintf(L"%s",a);
>>
>> }
>
> Well, at least the compiler isn't going to warn about the second
> case; you're using a string literal rather than a character constant,
> so you can have as many characters/bytes/glyphs between them as
> you like.
>
> What does wcslen(a) return?
>
> (Note that, in my newsreader, your string literal looks something like
> L"[][]"
> only fuzzier.)

Solved!

downloaded visual c++ express 2010 and compiled below code
with cl.exe and worked.

#include <locale.h>
#include <stdio.h>
#include <wchar.h>


main(){
wchar_t a = L'CN';
setlocale(LC_ALL, "kor");

putwchar(a);

}

Owner

2/11/2011 12:42:00 AM

0

On Thu, 10 Feb 2011 19:37:57 -0500, Owner wrote:

> On Thu, 10 Feb 2011 15:52:49 -0800, Keith Thompson wrote:
>
>> Owner <Owner@Owner-PC.com> writes:
>>> On Thu, 10 Feb 2011 07:21:54 -0500, Owner wrote:
>>>> what's wrong with this code?
>>>>
>>>> #include <locale.h>
>>>> #include <stdio.h>
>>>> #include <wchar.h>
>>>>
>>>> main(){
>>>> setlocale(LC_CTYPE, "");
>>>> wchar_t a = L'CN';
>>>> putwchar(a);
>>>>
>>>> }
>>>>
>>>> result
>>>>
>>>> test.c:7: warning: multi-character character constant
>>>
>>> Strangely this below code works then.
>>>
>>> #include <locale.h>
>>> #include <stdio.h>
>>> #include <wchar.h>
>>>
>>>
>>> main(){
>>> wchar_t *a = L"CN±U";
>>> setlocale(LC_ALL, "ko");
>>>
>>> wprintf(L"%s",a);
>>>
>>> }
>>
>> Well, at least the compiler isn't going to warn about the second
>> case; you're using a string literal rather than a character constant,
>> so you can have as many characters/bytes/glyphs between them as
>> you like.
>>
>> What does wcslen(a) return?

4


>>
>> (Note that, in my newsreader, your string literal looks something like
>> L"[][]"
>> only fuzzier.)

supposed to be korean in 2 letters

>
> Solved!
>
> downloaded visual c++ express 2010 and compiled below code
> with cl.exe and worked.
>
> #include <locale.h>
> #include <stdio.h>
> #include <wchar.h>
>
>
> main(){
> wchar_t a = L'CN';
> setlocale(LC_ALL, "kor");
>
> putwchar(a);
>
> }

Owner

2/11/2011 12:48:00 AM

0


>>>
>>> What does wcslen(a) return?
>
> 4
>
>
and visual c++ express 2010 cl.exe returns 2 which is correct
length of the string.