www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/12/19/08:21:36

From: "Michael N. Filippov" <michael AT idisys DOT iae DOT nsk DOT su>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Looks like GCC 2.95 bug
Date: 19 Dec 1999 12:46:33 GMT
Lines: 99
Message-ID: <83ik39$1klm$1@news.itfs.nsk.su>
References: <83b5qf$k5i$1 AT news DOT itfs DOT nsk DOT su> <38591F0C DOT 52CE1542 AT efd DOT lth DOT se> <83bg6q$do45 AT news DOT tis-in DOT trb>
NNTP-Posting-Host: idisys.iae.nsk.su
Mime-Version: 1.0
X-Trace: news.itfs.nsk.su 945607593 53942 193.124.169.11 (19 Dec 1999 12:46:33 GMT)
X-Complaints-To: usenet AT news DOT itfs DOT nsk DOT su
NNTP-Posting-Date: 19 Dec 1999 12:46:33 GMT
User-Agent: tin/pre-1.4-19990517 ("Psychonaut") (UNIX) (Linux/2.2.10-ac10 (i586))
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Steve Chapel <schapel AT breakthr DOT com> wrote:
> "Peter Danielsson" <e96pd AT efd DOT lth DOT se> wrote in message
> news:38591F0C DOT 52CE1542 AT efd DOT lth DOT se...
>> I dont think you can  do char *p="test";
>> p is a pointer. Try char p[]="test"; and &p[0] is the same as your p.

> Sure you can! In fact, C++ allows assigning a string literal to a non-const
> char * for compatability with old C programs. But I don't think passing a
> string literal to a non-const char * argument is allowed. In this case, the
> string literal is "" and func() has a non-const char * argument, so I
> believe gcc is correct in rejecting this code.

Hmm :(, let me put it in other words :
commented text _can_ be compiled - the question is "where is the difference"
---------------------------------------------------
idisys:/usr1/users/michael/tmp$ cat const.cpp
#include <stdio.h>

void    func(char* s)
{
  printf("%s'\n", s);
}

int  main(void)
{
  char  *p = "test string";     // NULL;
  if ( p == NULL )
    func("");
  else
    func(p);
//  func( ( p == NULL ) ? "" : p );
  return 0;
}

idisys:/usr1/users/michael/tmp$ gcc const.cpp
idisys:/usr1/users/michael/tmp$ gcc -v
Reading specs from /usr/lib/gcc-lib/i586-ksi-linux/2.95/specs
gcc version 2.95 19990728 (release)
idisys:/usr1/users/michael/tmp$

You see ?

>> "Michael N. Filippov" wrote:
>>
>> > Hello !
>> > I'm not sure it is the right place to ask - but it is the only C/C++
>> > conference i read, sorry.
>> >
>> > The question is: is this code correct according to the latest C++
> standards :)
>> > and difference between commented part and last func() call.
>> >
>> > idisys:/usr1/users/michael/tmp$ cat const.cpp
>> > #include <stdio.h>
>> >
>> > void    func(char* s)
>> > {
>> >   printf("func(%s)\n", s);
>> > }
>> >
>> > int  main(void)
>> > {
>> >   char  *p = "Test string";     // NULL;
>> > //  if ( p == NULL )
>> > //    func("");
>> > //  else
>> > //    func(p);
>> >   func( ( p == NULL ) ? "" : p );
>> >   return 0;
>> > }
>> >
>> > The problem is:
>> > idisys:/usr1/users/michael/tmp$ gcc const.cpp
>> > const.cpp: In function  nt main()':
>> > const.cpp:15: passing onst char *' as argument 1 of unc(char *)'
> discards
>> >  qualifiers
>> > idisys:/usr1/users/michael/tmp$ gcc -v
>> > Reading specs from /usr/lib/gcc-lib/i586-ksi-linux/2.95/specs
>> > gcc version 2.95 19990728 (release)
>> >
>> > Moreover I can compile it w/out problems
>> > woland:~/tmp$ gcc const.cpp
>> > woland:~/tmp$ gcc -v
>> > gcc version 2.7.2.1
>> >
>> > and
>> > [michael AT sig tmp]$ gcc const.cpp
>> > [michael AT sig tmp]$ gcc -v
>> > Reading specs from /usr/lib/gcc-lib/i586-ksi-linux/egcs-2.91.66/specs
>> > gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
>> >
>> > All the same with DJGPP.
>> >
>> > Sincerely,
>> > Michael
>>


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019