casting away multi-byte constants

I have a line of code that looks like this:
short x = ‘AB’;

With GNU I get a compiler warning. (That’s good. I like it when the
compiler tried to warn me about things.) But in this case I want to
tell the compiler that I know what I’m doing. I can’t seem to find a
way to cast away the warning.

Can this warning be cast away?


BTW, I also tried:
QCC -Wc,-Wmultichar myfile.cc

That didn’t work either. Although I don’t really want to turn that
warning off altogether, just for this one assignment.

Doesn’t appear so, I’m afraid. The code is, essentially

else if (chars_seen != 1 && warn_multichar)
warning (“multi-character character constant”);

Bill Caroselli <qtps@earthlink.net> wrote:

I have a line of code that looks like this:
short x = ‘AB’;

With GNU I get a compiler warning. (That’s good. I like it when the
compiler tried to warn me about things.) But in this case I want to
tell the compiler that I know what I’m doing. I can’t seem to find a
way to cast away the warning.

Can this warning be cast away?



BTW, I also tried:
QCC -Wc,-Wmultichar myfile.cc

That didn’t work either. Although I don’t really want to turn that
warning off altogether, just for this one assignment.


cburgess@qnx.com

I don’t think you can turn this on/off on a per instance basis (at least not
AFAICS from the docs for gcc). Multibyte character constants are dangerous
if you’re thinking of using the source elsewhere (since the interpretation
is implementation specific). Would it not be better to construct the
multibyte character at run time rather?

Just curious, why a ‘short’ to hold this multibyte char?

-Adam

Bill Caroselli <qtps@earthlink.net> wrote in message
news:b9924b$j26$1@inn.qnx.com

I have a line of code that looks like this:
short x = ‘AB’;

With GNU I get a compiler warning. (That’s good. I like it when the
compiler tried to warn me about things.) But in this case I want to
tell the compiler that I know what I’m doing. I can’t seem to find a
way to cast away the warning.

Can this warning be cast away?


BTW, I also tried:
QCC -Wc,-Wmultichar myfile.cc

That didn’t work either. Although I don’t really want to turn that
warning off altogether, just for this one assignment.

I used short because it is a field in a data base record. There are
many of them. There are about 12 different 2 letter codes. I want to
be able to ‘see’ them on disk, but not take up a whole lot of room to
document what kind of record this is that I’m looking at.

OK, I’ve already come up with alternative source code using defines.
But why didn’t my option to turn off that warning work with the
compiler? (I’m sure I just have the syntax wrong.) I wrote:
QCC -Wc,-Wmultichar myfile.cc

Note that this is a C++ file.

Adam Mallory <amallory@qnx.com> wrote:

AM > I don’t think you can turn this on/off on a per instance basis (at least not
AM > AFAICS from the docs for gcc). Multibyte character constants are dangerous
AM > if you’re thinking of using the source elsewhere (since the interpretation
AM > is implementation specific). Would it not be better to construct the
AM > multibyte character at run time rather?

AM > Just curious, why a ‘short’ to hold this multibyte char?

AM > -Adam

AM > Bill Caroselli <qtps@earthlink.net> wrote in message
AM > news:b9924b$j26$1@inn.qnx.com

I have a line of code that looks like this:
short x = ‘AB’;

With GNU I get a compiler warning. (That’s good. I like it when the
compiler tried to warn me about things.) But in this case I want to
tell the compiler that I know what I’m doing. I can’t seem to find a
way to cast away the warning.

Can this warning be cast away?


BTW, I also tried:
QCC -Wc,-Wmultichar myfile.cc

That didn’t work either. Although I don’t really want to turn that
warning off altogether, just for this one assignment.

Try -Wc,-Wno-multichar or -Wno-multichar

dB


Bill Caroselli wrote, ca. 6 May 2003 22:19:28 GMT:

I used short because it is a field in a data base record. There are
many of them. There are about 12 different 2 letter codes. I want to
be able to ‘see’ them on disk, but not take up a whole lot of room to
document what kind of record this is that I’m looking at.

OK, I’ve already come up with alternative source code using defines.
But why didn’t my option to turn off that warning work with the
compiler? (I’m sure I just have the syntax wrong.) I wrote:
QCC -Wc,-Wmultichar myfile.cc

Note that this is a C++ file.

Adam Mallory <> amallory@qnx.com> > wrote:

AM > I don’t think you can turn this on/off on a per instance basis (at least not
AM > AFAICS from the docs for gcc). Multibyte character constants are dangerous
AM > if you’re thinking of using the source elsewhere (since the interpretation
AM > is implementation specific). Would it not be better to construct the
AM > multibyte character at run time rather?

AM > Just curious, why a ‘short’ to hold this multibyte char?

AM > -Adam

AM > Bill Caroselli <> qtps@earthlink.net> > wrote in message
AM > news:b9924b$j26$> 1@inn.qnx.com> …

I have a line of code that looks like this:
short x = ‘AB’;

With GNU I get a compiler warning. (That’s good. I like it when the
compiler tried to warn me about things.) But in this case I want to
tell the compiler that I know what I’m doing. I can’t seem to find a
way to cast away the warning.

Can this warning be cast away?


BTW, I also tried:
QCC -Wc,-Wmultichar myfile.cc

That didn’t work either. Although I don’t really want to turn that
warning off altogether, just for this one assignment.

Bill,

Try this:

short x = L’AB’;

or:
wchart_t x = L’AB’;


Bernard



Bill Caroselli wrote:

I have a line of code that looks like this:
short x = ‘AB’;

With GNU I get a compiler warning. (That’s good. I like it when the
compiler tried to warn me about things.) But in this case I want to
tell the compiler that I know what I’m doing. I can’t seem to find a
way to cast away the warning.

Can this warning be cast away?


BTW, I also tried:
QCC -Wc,-Wmultichar myfile.cc

That didn’t work either. Although I don’t really want to turn that
warning off altogether, just for this one assignment.

Wasn’t that a Watcom extension?

At any rate L’AB’ didn’t help and type wchart_t isn’t recognized.

But thanks for trying.


Bernard Leclerc <whittom-leclerc@sympatico.ca> wrote:
BL > Bill,

BL > Try this:

BL > short x = L’AB’;

BL > or:
BL > wchart_t x = L’AB’;

Bill Caroselli <qtps@earthlink.net> wrote:
: Wasn’t that a Watcom extension?

: At any rate L’AB’ didn’t help and type wchart_t isn’t recognized.

I suspect he meant wchar_t.


Steve Reid stever@qnx.com
TechPubs (Technical Publications)
QNX Software Systems

Steve Reid <stever@qnx.com> wrote:
SR > Bill Caroselli <qtps@earthlink.net> wrote:
SR > : Wasn’t that a Watcom extension?

SR > : At any rate L’AB’ didn’t help and type wchart_t isn’t recognized.

SR > I suspect he meant wchar_t.


Thank you Steve.

That didn’t get rid of the warning either. But this has been very
educational for me.

Is the type ‘wchar_t’ a built-in type, line int?
Apparently so with GNU. I see it referenced all over the place but I
can’t find any place where it is defined.

ALso, I was not aware of the L’xx’ syntax at all. But the compiler does
seem to accept it with out any extra defines or manipulating.
Cool. But . . .

If the compiler does decognize the L’xx’ syntax but still gives the
warning about a multibyte constant, that sounds liek a GNU compiler
bug to me.

Would any of our compiler guru’s care to comment?

Bill Caroselli <qtps@earthlink.net> wrote:

Is the type ‘wchar_t’ a built-in type, line int?
Apparently so with GNU. I see it referenced all over the place but I
can’t find any place where it is defined.

I believe it’s built-in in C++, but not C - I could be mistaken about that.
C defines it in a couple of header files: stddef.h, stdlib.h for example.

ALso, I was not aware of the L’xx’ syntax at all. But the compiler does
seem to accept it with out any extra defines or manipulating.

It’s a standard C construct (as well as L"xxyyzz") - it makes the
character (or string) a wide character (or string).

If the compiler does decognize the L’xx’ syntax but still gives the
warning about a multibyte constant, that sounds liek a GNU compiler
bug to me.

No bug. In either case, it’s unspecified by the standard on whether ‘AB’
is compiled as:

(‘A’ << :sunglasses: + ‘B’
or
(‘B’ << :sunglasses: + ‘A’

and gcc’s just letting you know that.


Brian Stecher (bstecher@qnx.com) QNX Software Systems, Ltd.
phone: +1 (613) 591-0931 (voice) 175 Terence Matthews Cr.
+1 (613) 591-3579 (fax) Kanata, Ontario, Canada K2M 1W8

bstecher@qnx.com wrote:

ALso, I was not aware of the L’xx’ syntax at all. But the compiler does
seem to accept it with out any extra defines or manipulating.

bqc > It’s a standard C construct (as well as L"xxyyzz") - it makes the
bqc > character (or string) a wide character (or string).

If the compiler does decognize the L’xx’ syntax but still gives the
warning about a multibyte constant, that sounds liek a GNU compiler
bug to me.

bqc > No bug. In either case, it’s unspecified by the standard on whether ‘AB’
bqc > is compiled as:

bqc > (‘A’ << :sunglasses: + ‘B’
bqc > or
bqc > (‘B’ << :sunglasses: + ‘A’

bqc > and gcc’s just letting you know that.

OK. Is there an example where the L’xx’ syntax can be used without
generating a warning?

Bill Caroselli <qtps@earthlink.net> wrote:

OK. Is there an example where the L’xx’ syntax can be used without
generating a warning?

wchar_t foo = L’a’;


Brian Stecher (bstecher@qnx.com) QNX Software Systems, Ltd.
phone: +1 (613) 591-0931 (voice) 175 Terence Matthews Cr.
+1 (613) 591-3579 (fax) Kanata, Ontario, Canada K2M 1W8

bstecher@qnx.com wrote:

No bug. In either case, it’s unspecified by the standard on whether ‘AB’
is compiled as:

(‘A’ << > :sunglasses: > + ‘B’
or
(‘B’ << > :sunglasses: > + ‘A’

Actually, it’s implementation-defined (i.e. the compiler must document
what it is), but it doesn’t have to be one of the above. As far as the
C standard is concerned, a compiler can make it always the first
character, or always the last, or even make it always the value 255.