Quote:Original post by stylin
Quote:Original post by Zahlman
Quote:Original post by stylin
I may be mistaken but "t" is two bytes (one for the null). Try 't' instead.
It is four bytes which point at a sequence of two bytes, really. (Not to mention, it's of a completely different type.)
To recap:
const char * string_literal; // so string literals are interpreted this wayconst char * const string_literal; // or this way ?
Thanks for the clarification.
Too bad he's wrong.
cout << sizeof( "hi" ) << endl; //result: 3
A string literal's type would be:
const char string_literal[ string_literals_size ];
The fact that this can be used as a (const char * [const]) could does not make it that type, only convertable to that type. Other evidence you may notice would be the referencing of 'char [2]' in the error messages (not 'char *' - 'char [2]') as well as the fact that given the option between a reference to an array or a reference to a pointer, the compiler will choose the reference to an array:
#include <iostream>using namespace std;template < typename value_t , size_t size >void what_is_it( const value_t (&) [ size ] ){ cout << "An array of size " << size << endl;}template < typename value_t >void what_is_it( const value_t * )//or: what_is_it( const value_t * const )//or: what_is_it( const value_t * & )//or: what_is_it( const value_t * const & ){ cout << "A pointer" << endl;}int main () { what_is_it( "string literal" ); //result: An array of size 15}
[Edited by - MaulingMonkey on September 5, 2005 5:28:16 PM]