delorie.com/archives/browse.cgi | search |
From: | Damon Hogan <damonh AT pgmincorporated DOT com> |
Newsgroups: | comp.os.msdos.djgpp |
Subject: | Re: Looks like GCC 2.95 bug |
Date: | Wed, 22 Dec 1999 18:46:33 -0700 |
Organization: | XMission http://www.xmission.com/ |
Lines: | 79 |
Message-ID: | <38617EF9.6CBA7C24@pgmincorporated.com> |
References: | <83b5qf$k5i$1 AT news DOT itfs DOT nsk DOT su> |
NNTP-Posting-Host: | mail.pgmincorporated.com |
Mime-Version: | 1.0 |
X-Trace: | news.xmission.com 945913604 19593 166.70.119.101 (23 Dec 1999 01:46:44 GMT) |
X-Complaints-To: | abuse AT xmission DOT com |
NNTP-Posting-Date: | 23 Dec 1999 01:46:44 GMT |
X-Mailer: | Mozilla 4.6 [en] (Win98; I) |
X-Accept-Language: | en |
To: | djgpp AT delorie DOT com |
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
Reply-To: | djgpp AT delorie DOT com |
Well myself I use a string class include file & library which I mody to my hearts content to handle this situation. Using shrink and grow STring data type. If you are interested in the source let me know. #include <myString.H> int main(void) { STring bob; bob = "Does bob like candy?"; bob = "No."; bob = "Bob must be crasy\n"; cout << bob; } End result is that the bob instance of the STring class data type allocates enough memory to fit the new string each time the value is set and throws away the old memory location to be used for something else. Program prints Bob must be crazy "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
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |