Mail Archives: djgpp/2001/05/07/07:15:06
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 -