www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/05/07/07:15:06

Message-ID: <3AF680E1.46194490@falconsoft.be>
Date: Mon, 07 May 2001 13:02:57 +0200
From: Tim Van Holder <tim DOT vanholder AT falconsoft DOT be>
Organization: Falcon Software NV
X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.2.16-3 i686)
X-Accept-Language: en, nl-BE, nl
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: char* as default for constructor ?
References: <9cs59u$7r1$1 AT info DOT cyf-kr DOT edu DOT pl>
Lines: 51
NNTP-Posting-Host: 194.78.64.238
X-Trace: 989233367 reader1.news.skynet.be 43051 194.78.64.238
X-Complaints-To: abuse AT skynet DOT be
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Rafal Maj wrote:
> 
> Hi, I have 2 connected questions :
> 1) Is ther something wrong with using   char *s="test"    in arguments list
> of constructor, especialy, when I have separate definiton and declaration of
> constructor, like :
>   class ccc { ccc(char *S="abc") ; };
>   ccc::ccc(char *S="abc) { /* ... */ }
Not really, though default values are normally only given in the
declaration,
not the definition (I think gcc even warns about that).

So if you have

class ccc { ccc(char* S = "abc"); };

then writing

ccc::ccc(char* s) { ... }

would use the previously declared default for s. No need to repeat it.

> 2) Is is quaranteed (<-- BTW. what's spelling of that word ?) that all
It's "guaranteed".

> strings (char*, const char*) in my project, that are same will have same
> adresses in memory ?
> Like :
>  ***inside library, that is liked into main***
>   char *a="abc", *b="abc";  const char *c="abc";
> ***main***
>   main()
> 
>     char *d="abc";
>     if ((a==b)&&(b==c)&&(c==d)) /* correct ! */  // ????
>   }
> 
Nope. Many compilers will probably optimize that way, but there's no
guarantee (especially if using -fwritable-strings in gcc).
If you want such behaviour, you'll need to use a global
variable/constant
instead.

> Thanx in advice...
I think you mean 'Thanks in advance' :-)

-- 
Tim Van Holder - Falcon Software N.V.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
This message was posted using plain text. I do not endorse any
products or services that may be hyperlinked to this message.

- Raw text -


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