Topic: Initialisation of char[]


Author: rfg@netcom.com (Ronald F. Guilmette)
Date: Mon, 18 Apr 1994 10:47:23 GMT
Raw View
In article <766402292snz@iplbath.demon.co.uk> mishad@iplbath.demon.co.uk writes:
>Can any one explain this to me:
>I am using Sun's C++ 3.0.1
>
>        char ch_ary[] = "string";                             // Fine
>        const char c_ch_ary[] = "constant string";            // Also fine
>
>        signed char ch_ary[] = "string";                      // Also Fine
>        const signed char c_ch_ary[] = "constant string";     // Also fine
>
>        unsigned char ch_ary[] = "string";                    // Also Fine
>        const unsigned char c_ch_ary[] = "constant string";   // Also fine
>
>So far so good - now try using typedefs to do essentially the same thing
>
>        typedef char Char;
>        typedef unsigned char SChar;
>        typedef signed char UChar;
>
>        Char ch_ary[] = "string";                             // Fine
>        const Char c_ch_ary[] = "constant string";            // Warning
>
>        SChar ch_ary[] = "string";                            // Fine
>        const SChar c_ch_ary[] = "constant string";           // Warning
>
>        UChar ch_ary[] = "string";                            // Warning
>        const UChar c_ch_ary[] = "constant string";           // Warning
>
>The warning is:
>        warning: {}-enclosed initializer required
>        warning: improper pointer/integer combination: op "="
>        non-constant initializer: op "SCONV"
>
>Is this behaviour correct?

It would seem so (by default).

The ANSI/ISO C standard very clearly says that a standard conforming
implementation is permitted to issue as many diagnostics as it likes,
so long as it correctly translates any strictly conforming program.

In contrast, the current draft C++ standard only says when an implementation
MUST issue a disgnostic.  It says very little else on the subject.

More specifically, it does not list any conditions under which a standard
conforming implementation MAY NOT issue diagnostics. Thus, by default, C++
implementations may issue a zillion warnings, a zillion errors, and may
also cause your monitor to implode (thereby showering you with shards of
broken glass)... and they may do all this under any conditions they please,
so long as they `accept and correctly execute' any of your valid programs.

(I can't wait to see the first compiler that claims to fulfill this require-
ment.  How can it know what *my* definition of `correct execution' is??? :-)

--

-- Ron Guilmette, Sunnyvale, CA ---------- RG Consulting -------------------
---- domain addr: rfg@netcom.com ----------- Purveyors of Compiler Test ----
---- uucp addr: ...!uunet!netcom!rfg ------- Suites and Bullet-Proof Shoes -




Author: mishad@iplbath.demon.co.uk (Misha Dorman)
Date: Fri, 15 Apr 1994 09:31:32 +0000
Raw View
Can any one explain this to me:
I am using Sun's C++ 3.0.1

        char ch_ary[] = "string";                             // Fine
        const char c_ch_ary[] = "constant string";            // Also fine

        signed char ch_ary[] = "string";                      // Also Fine
        const signed char c_ch_ary[] = "constant string";     // Also fine

        unsigned char ch_ary[] = "string";                    // Also Fine
        const unsigned char c_ch_ary[] = "constant string";   // Also fine

So far so good - now try using typedefs to do essentially the same thing

        typedef char Char;
        typedef unsigned char SChar;
        typedef signed char UChar;

        Char ch_ary[] = "string";                             // Fine
        const Char c_ch_ary[] = "constant string";            // Warning

        SChar ch_ary[] = "string";                            // Fine
        const SChar c_ch_ary[] = "constant string";           // Warning

        UChar ch_ary[] = "string";                            // Warning
        const UChar c_ch_ary[] = "constant string";           // Warning

The warning is:
        warning: {}-enclosed initializer required
        warning: improper pointer/integer combination: op "="
        non-constant initializer: op "SCONV"

Is this behaviour correct?

Thanks,
Misha
--


Misha Dorman
IPL Information Processing Ltd
Eveleigh House                   Tel: +44 (0)225 444888
Grove Street                     Fax: +44 (0)225 444400
Bath  BA1 5LR
United Kingdom       E-mail: mishad@iplbath.demon.co.uk