List:Commits« Previous MessageNext Message »
From:Dmitry Shulga Date:September 7 2010 5:01pm
Subject:Re: bzr commit into mysql-5.1-bugteam branch (Dmitry.Shulga:3456)
Bug#47485
View as plain text  
Hi Davi!

> On 9/7/10 1:34 AM, Dmitry Shulga wrote:
>>>> +  MYSQL_RES    *res;
>>>>>> +  MYSQL_BIND    bind[2]; +  int           rc; +  const char*
>>>>>> sql_select = "SELECT 1, 'a'";
>>>> 
>>>> const char sql_select[]= "SELECT 1, 'a'";
>> Left as is since const char* is better type for a character literal.
> 
> sql_select in your patch is just a pointer, whereas what I suggested is a array. A
> array is certainly a "better" type to hold a array of characters. Also, the pointer is
> useless as nothing is being assigned to it afterward, yet its a full blown variable.
Lets consider statement 
const char* sql_select = "SELECT 1, 'a'";
"SELECT 1, 'a'" is a string literal. In accordance with C++ language standard (ISO/IEC
14882) an ordinary string literal has type “array of n
const char” and static storage duration, where n is the size of the string as
defined below, and is
initialized with the given characters. (clause 2.13.4)
sql_select is just name for this string literal.
I can make this variable declaration more strong and declare sql_select as

 const char* const sql_select = "SELECT 1, 'a'";
In any case sql_select is just label name for this string literal value.

On the other hand If we declare sql_select as 
const char sql_select[] = "SELECT 1, 'a'";
we have array with name sql_select and this array filled by byte values from array
corresponding to string literal value "SELECT 1, 'a'".

I think this is not best approach.

> Even if my concern was performance (I was looking at the type), I don't think a
> pointer is any better. By using the array approach, we save one pointer in the
> non-shareable data segment and relocation to initialize the variable with a pointer to the
> string. Also, it allows the compiler to know that the array will never change and one
> could also use sizeof on it instead of strlen on the pointer.
The only positive effect for use const char [] is that you can use sizeof instead of
strlen. Here you are right.

Regards,
Dmitry.
Thread
bzr commit into mysql-5.1-bugteam branch (Dmitry.Shulga:3456) Bug#47485Dmitry Shulga29 Jul
  • Re: bzr commit into mysql-5.1-bugteam branch (Dmitry.Shulga:3456)Bug#47485Davi Arnaut6 Sep
    • Re: bzr commit into mysql-5.1-bugteam branch (Dmitry.Shulga:3456)Bug#47485Dmitry Shulga7 Sep
      • Re: bzr commit into mysql-5.1-bugteam branch (Dmitry.Shulga:3456)Bug#47485Davi Arnaut7 Sep
        • Re: bzr commit into mysql-5.1-bugteam branch (Dmitry.Shulga:3456)Bug#47485Dmitry Shulga7 Sep
          • Re: bzr commit into mysql-5.1-bugteam branch (Dmitry.Shulga:3456)Bug#47485Davi Arnaut7 Sep
          • Re: bzr commit into mysql-5.1-bugteam branch (Dmitry.Shulga:3456)Bug#47485Bjorn Munch8 Sep
            • Re: bzr commit into mysql-5.1-bugteam branch (Dmitry.Shulga:3456)Bug#47485Dmitry Shulga9 Sep