On 9/7/10 1:34 AM, Dmitry Shulga wrote:
>>> + MYSQL_RES *res;
>>>>> + MYSQL_BIND bind; + 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.
> const char * points to some data allocated in data segment whereas
> const char array will be initialized every time when function
If this was a concern, you can explicitly put it in the data segment with:
static const char sql_select= "SELECT 1, 'a'";
which has the advantages highlighted below if we are looking into
> called. So const char* is better way to declare character literal
> from the point of cpu perfomance and memory usage.
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.