This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC] std::string(0);


On Tue, 2004-06-15 at 13:29, Daniel Frey wrote:
> Loren James Rittle wrote:
> > In article <1087279330.1403.0.camel@localhost.localdomain>,
> > Dhruv Matani<dhruvbird@gmx.net> writes:
> > 
> > 
> >>>>BTW, would "" be equivalent to '\0'?
> > 
> > 
> > "" is a pointer.  '\0' is a character.
> 
> "" is an array of const char, not a pointer. The difference can be seen 
> here:

Yes, but the point that Loren is trying to make(I think) is that you can
treat "blah blah" as a pointer to const for *most* practical purposes,
like dereferencing, etc...


> 
> template< int N >
> void f( const char(&)[N] ) {}
> 
> int main() {
>    const char* p = "";

Like in the above statement, you have treated "" like a pointer, and
assigned it to the pointer variable p.

Now, after all this is over, I recall vaguely that on c.l.c++.m, there
was a discussion about the above style of initialization that you have
made, and many think that it should be depricated.

However, using "blah blah" as a pointer and dereferencing it like 
"blah blah"[1] is something I have seen for the first time!

C++ never ceases to amaze me with the number of gotchas and neat tricks
that I get to learn almost every single day!

>    f( "" );
>    f( p );
> }
> 
> Regards, Daniel
-- 
        -Dhruv Matani.
http://www.geocities.com/dhruvbird/

Proud to be a Vegetarian.
http://www.vegetarianstarterkit.com/
http://www.vegkids.com/vegkids/index.html



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]